📄 winpublic.cs
字号:
{
System.Windows.Forms.Control obj1=new System.Windows.Forms.Control ();
foreach(System.Windows.Forms.Control obj in ParentObj.Controls)
{
if(obj.TabIndex ==TabIndex)
{
obj1=obj;
return obj1;
}
}
return null;
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return null;
}
}
//设置控件的傎,完成格式转换
public bool IsValidInput(System.Windows.Forms.Control ParentObj,string HeaderTexts)
{
try
{
string[] Texts=HeaderTexts.Split('|');
//string ErroyInfo="";
System.Windows.Forms.Control CurrObj=new System.Windows.Forms.Control ();
for(int i=0;i<Texts.Length ;i++)
//需要检证的列
if (Texts[i].Trim().Length!=Texts[i].Length)
{
CurrObj=GetTabIndexControl(ParentObj,i);
if (CurrObj.Text==string.Empty || CurrObj.Text==null)
{
string ErroyInfo="【"+Texts[i].Trim()+"】不能为空,请重新输入"+Texts[i].Trim()+"!";
MessageBox.Show(ErroyInfo);
CurrObj.Focus();
return false;
}
//break;
}
return true;
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return false;
}
}
//取控件的值
private object GetControlValue(System.Windows.Forms.Control obj)
{
try
{
string objName=obj.GetType().Name;
switch(objName)
{
case "ComboBox":
ComboBox ComboBox1=obj as ComboBox;
return ComboBox1.Text;
case "CheckBox":
CheckBox CheckBox1=(CheckBox)obj;
return CheckBox1.Checked ;
case "RadioButton":
RadioButton RadioButton1=obj as RadioButton;
return RadioButton1.Checked;
case "TextBox":
return obj.Text;
case "UpDownButtons":
return obj.Text;
case "NumericUpDown":
NumericUpDown NumericUpDown1=(NumericUpDown)obj;
return NumericUpDown1.Value;
case "DateTimePicker":
//varValue = Format(obj.value, "short Date");
return System.Convert.ToDateTime(obj.Text).ToShortDateString();
case "DTPicker":
//varValue = Format(obj.value, "short Date");
return obj.Text;
case "TDBNumber":
return obj.Text;
case "TDBDate":
return obj.Text;
//varValue = obj.value;
case "ListBox":
return obj.Text;
default:
return obj.Text;
}
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return false;
}
}
//取控件的值
public object GetPrimaryKeyValue(System.Windows.Forms.Control obj)
{
try
{
System.Windows.Forms.Control obj1=GetTabIndexControl(obj,0);
return GetControlValue(obj1);
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return null;
}
}
// '检查控件数据是否有效,没错则返回true.
public bool IsVaildControlData(System.Windows.Forms.Control obj,string FieldText,string checkValue)
{
try
{
object varValue=GetControlValue(obj);
string ErroyInfo="【"+FieldText+"】不能为空,请重新输入"+FieldText+"!";
if( checkValue ==string.Empty )
{
if ((string)varValue=="")
{
MessageBox.Show(ErroyInfo);
if(obj.Enabled == true)
obj.Focus();
return false;
}
}
else
{
if( (string)varValue != checkValue)
{
ErroyInfo="【"+FieldText+"】的值不能为【" + checkValue + " 】!请重新设置它的值!";
MessageBox.Show(ErroyInfo);
if(obj.Enabled == true)
obj.Focus();
return true;
}
}
return true;
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return false;
}
}
//把网络计算机的IP地址填入ComboBox
public void FillIPAddress (System.Windows.Forms.ComboBox ComboBox1)
{
try
{
string HostName=GetHostName();
IPAddress[] IPs=GetHostAddress(HostName);
for (int i=0;i<IPs.Length;i++)
ComboBox1.Items.Add(IPs[i].ToString());
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return ;
}
}
//设置DataGrid的各列标题
public static DataGridTableStyle SetDataGridHeaderText(DataGrid DataGrid1,string HeaderText)
{
try
{
DataTable dt=DataGrid1.DataSource as DataTable ;
string[] HeaderTexts=HeaderText.Split('|');
DataGridTableStyle myGridTableStyle1=new DataGridTableStyle();
myGridTableStyle1.MappingName=dt.TableName;
DataGrid1.TableStyles.Clear();
DataGrid1.TableStyles.Add(myGridTableStyle1);
myGridTableStyle1.SelectionBackColor=System.Drawing.Color .Blue;
// DataGrid1.DataSource= dt;
for(int i=0;i<HeaderTexts.Length ;i++)
{
if(i<myGridTableStyle1.GridColumnStyles.Count)
myGridTableStyle1.GridColumnStyles[i].HeaderText=HeaderTexts[i].Trim();
if(HeaderTexts[i].Trim()!="")
{
int len=HeaderTexts[i].Length;
myGridTableStyle1.GridColumnStyles[i].Width=10*len+30;
// Graphics mGraphics=new Graphics ();
// myGridTableStyle1.GridColumnStyles[i].Width=cmGraphics.MeasureCharacterRanges(HeaderTexts[i]).Length+50;
}
else
myGridTableStyle1.GridColumnStyles[i].Width=0;
}
// HighLightCurrentRow( DataGrid1);
if (DataGrid1.DataSource==null) return myGridTableStyle1;
if (((DataTable)DataGrid1.DataSource).Rows.Count==0) return myGridTableStyle1;
if (DataGrid1.CurrentRowIndex==-1) DataGrid1.CurrentRowIndex=0;
// if (DataGrid1.CurrentRowIndex!=-1)
// {
// //DataGrid1.Select(DataGrid1.CurrentRowIndex);
// }
return myGridTableStyle1;
}
catch(Exception ex)
{
//FileTool.HandleErr( new PopedomException(MessageBox.Show (ex.ToString ()));
System.Windows .Forms .MessageBox.Show (ex.ToString ());
return null;
}
}
public void HighLightCurrentRow( DataGrid dg)
{
try
{
if (dg.DataSource==null) return;
if (((DataTable)dg.DataSource).Rows.Count==0) return;
if (dg.CurrentRowIndex==-1) dg.CurrentRowIndex=0;
if (dg.CurrentRowIndex!=-1)
{
dg.Select(dg.CurrentRowIndex);
}
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return ;
}
}
public static string txt;
public void SetFormEnabled( System.Windows .Forms.Form frm,System.Windows.Forms.Control obj,bool IsEnabled)
{
try
{
if(!IsEnabled)
{
frm.Cursor =System.Windows .Forms.Cursors.WaitCursor;
txt=obj.Text;
obj.Text ="请稍候...";
}
else
{
frm.Cursor =System.Windows .Forms.Cursors.Default ;
obj.Text =txt;
}
frm.Enabled =IsEnabled;
// foreach(System.Windows.Forms.Control obj in frm.Controls)
// {
// obj.Enabled = IsEnabled;
// }
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return ;
}
}
public void SetFormEnabled( System.Windows .Forms.Form frm,System.Windows.Forms.ToolBarButton obj,bool IsEnabled)
{
try
{
//string txt=obj.Text;
if(!IsEnabled)
{
frm.Cursor =System.Windows .Forms.Cursors.WaitCursor;
txt=obj.Text;
//obj.Text ="请稍候...";
}
else
{
frm.Cursor =System.Windows .Forms.Cursors.Default ;
//obj.Text =txt;
}
frm.Enabled =IsEnabled;
// foreach(System.Windows.Forms.Control obj in frm.Controls)
// {
// obj.Enabled = IsEnabled;
// }
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return ;
}
}
public DataSet ExceuteSQL(string SQL)
{
try
{
PersistenceManager pm=PersistenceManagerFactory.Instance().CreatePersistenceManager();
//EntityData entity=EntityPrototypeManager.GetEmptyEntity(this.EntityTypeName,pp);
// Query q=pm.NewQuery(SQL);
// q.Open();
DataAccess dao=pm.NewDataAccess();
DataSet entity= dao.ExecuteDataset(SQL);
//EntityData entity=q.QueryData();
//EntityData entity=(EntityData)ds;
// q.Close();
// pm.Close();
return entity;
}
catch(Exception ex)
{
FileTool.HandleErr( new PopedomException(ex,"执行查询语句错!"));
return null;
}
}
////把数据表的一列数据填充ComBox
public void FillComboBoxByDataColumn(DataColumn Column1,ComboBox ComBox1)
{
try
{
if(Column1==null) return;
if(Column1.Table.Rows.Count <=0) return;
if(ComBox1.Items.Count==0)ComBox1.Items.Add (Column1.Table.Rows[0][Column1.ColumnName]);
for (int i=1;i<Column1.Table.Rows.Count;i++)
{
object obj=Column1;
for (int j=0;j<ComBox1.Items.Count;j++)
if (ComBox1.Items[j]==obj)
goto aa;
ComBox1.Items.Add (Column1.Table.Rows[i][Column1.ColumnName]);
aa:;
}
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return ;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -