📄 mymodule.cs
字号:
/// <param name="TName">获取信息控件的部份名称</param>
public void Show_DGrid(DataGridView DGrid, Control.ControlCollection GBox, string TName)
{
string sID = "";
if (DGrid.RowCount > 0)
{
for (int i = 2; i < DGrid.ColumnCount; i++)
{
sID = TName + i.ToString();
foreach (Control C in GBox)
{
if (C.GetType().Name == "TextBox" | C.GetType().Name == "MaskedTextBox" | C.GetType().Name == "ComboBox")
if (C.Name == sID)
{
if (C.GetType().Name != "MaskedTextBox")
C.Text = DGrid[i, DGrid.CurrentCell.RowIndex].Value.ToString();
else
C.Text = Date_Format(Convert.ToString(DGrid[i, DGrid.CurrentCell.RowIndex].Value).Trim());
}
}
}
}
}
#endregion
#region 清空控件集上的控件信息
/// <summary>
/// 清空GroupBox控件上的控件信息.
/// </summary>
/// <param name="n">控件个数</param>
/// <param name="GBox">GroupBox控件的数据集</param>
/// <param name="TName">获取信息控件的部份名称</param>
public void Clear_Grids(int n, Control.ControlCollection GBox, string TName)
{
string sID = "";
for (int i = 2; i < n; i++)
{
sID = TName + i.ToString();
foreach (Control C in GBox)
{
if (C.GetType().Name == "TextBox" | C.GetType().Name == "MaskedTextBox" | C.GetType().Name == "ComboBox")
if (C.Name == sID)
{
C.Text = "";
}
}
}
}
#endregion
#region 控制数据表的显示字段
/// <summary>
/// 通过条件显示相关表的字段,因使用DataGridView控件,添加System.Windows.Forms命名空间
/// </summary>
/// <param name="DSet">DataSet类</param>
/// <param name="DGrid">DataGridView控件</param>
public void Correlation_Table(DataSet DSet, DataGridView DGrid)
{
DGrid.DataSource = DSet.Tables[0];
DGrid.Columns[0].Visible = false;
DGrid.Columns[1].Visible = false;
DGrid.RowHeadersVisible = false;
DGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
#endregion
#region 组合查询条件
/// <summary>
/// 根据控件是否为空组合查询条件.
/// </summary>
/// <param name="GBox">GroupBox控件的数据集</param>
/// <param name="TName">获取信息控件的部份名称</param>
/// <param name="TName">查询关系</param>
public void Find_Grids(Control.ControlCollection GBox, string TName, string ANDSign)
{
string sID = ""; //定义局部变量
if (FindValue.Length>0)
FindValue = FindValue + ANDSign;
foreach (Control C in GBox){ //遍历控件集上的所有控件
if (C.GetType().Name == "TextBox" | C.GetType().Name == "ComboBox"){ //判断是否要遍历的控件
if (C.GetType().Name == "ComboBox" && C.Text!=""){ //当指定控件不为空时
sID = C.Name;
if (sID.IndexOf(TName) > -1){ //当TName参数是当前控件名中的部分信息时
string[] Astr = sID.Split(Convert.ToChar('_')); //用“_”符号分隔当前控件的名称,获取相应的字段名
FindValue = FindValue + "(" + Astr[1] + " = '" + C.Text + "')" + ANDSign; //生成查询条件
}
}
if (C.GetType().Name == "TextBox" && C.Text != "") //如果当前为TextBox控件,并且控件不为空
{
sID = C.Name; //获取当前控件的名称
if (sID.IndexOf(TName) > -1) //判断TName参数值是否为当前控件名的子字符串
{
string[] Astr = sID.Split(Convert.ToChar('_')); //以“_”为分隔符,将控件名存入到一维数组中
string m_Sgin = ""; //用于记录逻辑运算符
string mID = ""; //用于记录字段名
if (Astr.Length > 2) //当数组的元素个数大于2时
mID = Astr[1] + "_" + Astr[2]; //将最后两个元素组成字段名
else
mID = Astr[1]; //获取当前条件所对应的字段名称
foreach (Control C1 in GBox) //遍历控件集
{
if (C1.GetType().Name == "ComboBox") //判断是否为ComboBox组件
if ((C1.Name).IndexOf(mID) > -1) //判断当前组件名是否包含条件组件的部分文件名
{
if (C1.Text == "") //当查询条件为空时
break; //退出本次循环
else
{
m_Sgin = C1.Text; //将条件值存储到m_Sgin变量中
break;
}
}
}
if (m_Sgin != "") //当该务件不为空时
FindValue = FindValue + "(" + mID + m_Sgin + C.Text + ")" + ANDSign; //组合SQL语句的查询条件
}
}
}
}
if (FindValue.Length > 0) //当存储查询条的变量不为空时,删除逻辑运算符AND和OR
{
if (FindValue.IndexOf("AND") > -1) //判断是否用AND连接条件
FindValue = FindValue.Substring(0, FindValue.Length - 4);
if (FindValue.IndexOf("OR") > -1) //判断是否用OR连接条件
FindValue = FindValue.Substring(0, FindValue.Length - 3);
}
else
FindValue = "";
}
#endregion
#region 判断字符型日期是否正确
/// <summary>
/// 将字符型日期转换成日期进行判断.
/// </summary>
/// <param name="MTbox">MaskedTextBox控件</param>
/// <param name="NDate">字符型日期</param>
/// <>
public bool Estimate_Date(MaskedTextBox MTbox)
{
try
{
DateTime DT = DateTime.Parse(MTbox.Text.Trim());
return true;
}
catch
{
MTbox.Text = "";
MessageBox.Show("日期输入错误,请重新输入!");
return false;
}
}
#endregion
#region 设置文本框只能输入数字型字符串
/// <summary>
/// 文本框只能输入数字型和单精度型的字符串.
/// </summary>
/// <param name="e">KeyPressEventArgs类</param>
/// <param name="s">文本框的字符串</param>
/// <param name="n">标识,判断是数字型还是单精度型</param>
public void Estimate_Key(KeyPressEventArgs e,string s,int n)
{
if (n==0) //只能输入整型
if (!(e.KeyChar <= '9' && e.KeyChar >= '0') && e.KeyChar != '\r' && e.KeyChar != '\b')
{
e.Handled = true; //处理KeyPress事件
}
if (n == 1) //可以输入整型或单精度型
{
if ((!(e.KeyChar <= '9' && e.KeyChar >= '0')) && e.KeyChar != '.' && e.KeyChar != '\r' && e.KeyChar != '\b')
{
e.Handled = true;
}
else
{
if (e.KeyChar == '.') //如果输入“.”
if (s == "") //当前文本框为空
e.Handled = true; //处理KeyPress事件
else
{
if (s.Length > 0) //当文本框不为空时
{
if (s.IndexOf(".") > -1) //查找是否已输入过“.”
e.Handled = true; //处理KeyPress事件
}
}
}
}
}
#endregion
#region 添加用户权限
/// <summary>
/// 在添加用户时,将权限模版中的信息添加到用户权限表中.
/// </summary>
/// <param name="ID">用户编号</param>
/// <param name="n">权限值</param>
/// <>
public void ADD_Pope(string ID,int n)
{
DataSet DSet;
DSet = MyDataClass.getDataSet("select PopeName from tb_PopeModel", "tb_PopeModel");
for (int i = 0; i < DSet.Tables[0].Rows.Count; i++)
{
MyDataClass.getsqlcom("insert into tb_UserPope (ID,PopeName,Pope) values('" + ID + "','" + Convert.ToString(DSet.Tables[0].Rows[i][0]) + "'," + n + ")");
}
}
#endregion
#region 清空所有数据表
/// <summary>
/// 清空数据库中的所有数据表.
/// </summary>
/// <param name="GBox">GroupBox控件的数据集</param>
/// <param name="TName">获取信息控件的部份名称</param>
public void Clear_Table(Control.ControlCollection GBox, string TName)
{
string sID = "";
foreach (Control C in GBox)
{
if (C.GetType().Name == "CheckBox")
{
sID = C.Name;
if (sID.IndexOf(TName) > -1)
{
if (((CheckBox)C).Checked == true)
{
string TableName = "";
string[] Astr = sID.Split(Convert.ToChar('_'));
TableName = "tb_" + Astr[1];
if (Astr[1].ToUpper() == ("Clew").ToUpper())
{
MyDataClass.getsqlcom("update " + TableName + " set Fate=0,Unlock=0 where ID>0");
}
else
{
MyDataClass.getsqlcom("Delete " + TableName);
if (Astr[1].ToUpper() == ("Login").ToUpper())
{
MyDataClass.getsqlcom("Delete tb_UserPope");
MyDataClass.getsqlcom("insert into " + TableName + " (ID,Name,Pass) values('0001','TSoft','111')");
ADD_Pope("0001", 1);
}
}
}
}
}
}
}
#endregion
#region 显示用户权限
/// <summary>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -