/// <summary> /// 验证输入的是否正确 /// </summary> /// <param name="property"></param> /// <param name="ValueStr"></param> /// <returns></returns> private bool checkValudate(StimControlProperty property, string ValueStr, Hashtable htItem) { bool ch = true; if (property.CheckRegular != null) { PropertyGrid.Item.SYSMethod Method = new PropertyGrid.Item.SYSMethod(); //0,系统方法;1,正则表达式;2,sql语句 switch (property.CheckRegular.ValueType) { case "0": ch = Method.CheckValue(property.CheckRegular.ValueApp, ValueStr); break; case "1": ch = Method.RegexCheck(ValueStr, property.CheckRegular.ValueRegular); break; case "2": string sql = property.CheckRegular.ValueSql; Hashtable ht = new Hashtable(); //ht.Add(property.Name, ValueStr); //获取系统默认值 PropertyGrid.Item.SysValue _sysValue = new PropertyGrid.Item.SysValue(); foreach (PropertyGrid.TxtValObject obj in _sysValue.ValueList) { if (sql.IndexOf(":" + obj.Val) > 0) { ht.Add(obj.Val, _sysValue.GetValue(obj.Val)); } } //获取界面其他控件的值 foreach (DictionaryEntry objDE in htItem) { StimControlProperty tempProperty = objDE.Key as StimControlProperty; if (sql.IndexOf(":" + tempProperty.Name) > 0) { ht.Add(tempProperty.Name, objDE.Value); } } ch = (new BLL.STIM_CONFIG()).SqlCheckValue(sql, ht); break; } } return(ch); }
/// <summary> /// 修改数据 /// </summary> /// <param name="controls">控件集合</param> /// <param name="result">返回值</param> public void ModifyData(Control.ControlCollection controls, ref object result) { StringBuilder sbUpdateSql = new StringBuilder("update " + TableName + " set "); StringBuilder sbKeyValue = new StringBuilder(); StringBuilder sbWhere = new StringBuilder(" where 1=1 "); //获取填写的值 Hashtable htItem = new Hashtable(); CreateStimControl csc = new CreateStimControl(); foreach (StimControl item in controls) { DataRow row = DtStruct.Select("COLUMN_NAME='" + item.Name + "'")[0]; string value = csc.GetValueByType(item.DataFile); //如果不是主键 if (!PkList.Contains(item.Name)) { //值为空(此处''表示为空) if (string.IsNullOrEmpty(value.ToString())) { //if (row["Nullable"].ToString() == "N" || item.property.ControlRequired == 1)XElement xEl = xElement.Single(el => (string)el.Attribute("Column_Name") == item.Name).Elements("DataRule").Single(); //字段不能为空 if (row["Nullable"].ToString() == "N" || item.property.ControlRequired == 1) { MessageBox.Show(item.lblFile.Text + " 不能为空!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); result = "error"; return; } } //值不为空 else { ; sbKeyValue.Append("," + item.Name); string type = row["DATA_TYPE"].ToString(); if (type.Equals("NUMBER")) { sbKeyValue.Append("=" + value); } else if (type.Equals("DATE") || type.ToUpper().IndexOf("TIMESTAMP") == 0) { sbKeyValue.Append("=to_date('" + value + "','YYYY-MM-DD HH24:MI:SS')"); } else if (value.ToString().ToLower().Equals("sysdate")) { sbKeyValue.Append("=" + value); } else { sbKeyValue.Append("='" + value + "'"); } } } else { sbWhere.Append(" and " + item.Name); sbWhere.Append("='" + value + "'"); } htItem.Add(item.property, value); } sbKeyValue.Remove(0, 1);//移除第一个逗号 sbUpdateSql.Append(sbKeyValue); sbUpdateSql.Append(sbWhere); //数据验证格式和正确性验证 foreach (DictionaryEntry objDE in htItem) { string val = objDE.Value.ToString(); StimControlProperty property = objDE.Key as StimControlProperty; //验证输入值 if (!checkValudate(property, val, htItem)) { MessageBox.Show(property.Text + " 输入值错误!", "提示消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); result = "error"; return; } } result = _bll.UpdateData(sbUpdateSql.ToString()); }