Beispiel #1
0
        /// <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());
        }