public static void GetUIValue(MAction action, Control panel1, RowStatus rowState) { for (int i = 0; i < panel1.Controls.Count; i++) { IMyControl mc = panel1.Controls[i] as IMyControl; if (mc != null) { string text = mc.GetText(); if (rowState == RowStatus.Add) { if (text != "") { action.Set(panel1.Controls[i].Name, text); } } else { action.Set(panel1.Controls[i].Name, text); } } } }
public static string CheckValid(MAction action, Control panel1, RowStatus rowState, ErrorProvider ep) { if (ep != null) { ep.Clear(); } for (int i = 0; i < panel1.Controls.Count; i++) { IMyControl mc = panel1.Controls[i] as IMyControl; if (mc != null) { if (panel1.Controls[i].Visible) { if (!action.Data[panel1.Controls[i].Name].Struct.IsCanNull && mc.GetText() == "") { mc.SetInValid(); if (ep != null) { ep.SetError(panel1.Controls[i], "不能为空"); } return("不能为空"); } SqlDbType dbtype = action.Data[panel1.Controls[i].Name].Struct.SqlType; if (dbtype == SqlDbType.Decimal || dbtype == SqlDbType.Float || dbtype == SqlDbType.Int || dbtype == SqlDbType.Money || dbtype == SqlDbType.Real || dbtype == SqlDbType.SmallInt || dbtype == SqlDbType.SmallMoney || dbtype == SqlDbType.TinyInt) { double d = 0; if (mc.GetText() != "" && !double.TryParse(mc.GetText(), out d)) { if (ep != null) { ep.SetError(panel1.Controls[i], "不能转化为数字"); } return("不能转化为数字"); } } if (dbtype == SqlDbType.DateTime || dbtype == SqlDbType.DateTime2 || dbtype == SqlDbType.Date || dbtype == SqlDbType.SmallDateTime) { DateTime dt = DateTime.MinValue; if (mc.GetText() != "" && !DateTime.TryParse(mc.GetText(), out dt)) { if (ep != null) { ep.SetError(panel1.Controls[i], "不能转化为日期"); } return("不能转化为日期"); } } } } } return(""); }