Ejemplo n.º 1
0
        public bool WriteEntity(MD_InputEntity _entity)
        {
            bool _ret = false;

            using (SqlConnection cn = SqlHelper.OpenConnection())
            {
                SqlTransaction _txn = cn.BeginTransaction();
                try
                {
                    if (_entity.IsNewData)
                    {
                        _ret = WriteNewEntity(_entity, cn);
                    }
                    else
                    {
                        _ret = UpdateEntity(_entity, cn);
                    }

                    if (_ret)
                    {
                        _txn.Commit();
                        _entity.IsNewData = false;
                        if (InputModel.IsMixModel)
                        {
                            foreach (MD_InputModel_Child _child in InputModel.ChildInputModel)
                            {
                                switch (_child.ChildModel.ModelType)
                                {
                                case "FORM":

                                    break;

                                case "GRID":
                                    //DataTable _gridData = _entity.ChildInputData[_child.ID] as DataTable;
                                    //if (_gridData != null) _gridData.AcceptChanges();
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        _txn.Rollback();
                    }
                    return(_ret);
                }
                catch (Exception ex)
                {
                    _txn.Rollback();
                    string _errmsg = string.Format("采用录入模型写入数据出错!错误信息:{0}!", ex.Message);
                    //LogWriter.WriteSystemLog(_errmsg, "ERROR");
                    return(false);
                }
                cn.Close();
            }
        }
Ejemplo n.º 2
0
        //变量替换
        private string ConvertVar(string _method, MD_InputEntity _entity)
        {
            string _ret = _method;

            _ret = OraQueryBuilder.ReplaceExtSecret(_ret, "");
            foreach (string _key in _entity.InputData.Keys)
            {
                string _varName = string.Format("${0}$", _key);
                string _value   = string.Format("'{0}'", (_entity.InputData[_key] == null) ? "" : _entity.InputData[_key].ToString());
                _ret = _ret.Replace(_varName, _value);
            }
            return(_ret);
        }
Ejemplo n.º 3
0
 public void InitForm(MD_InputModel inputModelDefine, MD_InputEntity entity)
 {
     InputModelDefine = inputModelDefine;
     CurrentEntity    = entity;
     if (InputModelDefine.Groups.Count > 0)
     {
         CreateGroupsForm();
     }
     else
     {
         CreateSingleForm();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 写入新的记录
        /// </summary>
        /// <param name="_entity"></param>
        /// <returns></returns>
        private bool WriteNewEntity(MD_InputEntity _entity, SqlConnection cn)
        {
            foreach (MD_InputModel_SaveTable _table in InputModel.WriteTableNames)
            {
                WriteNewTableData(_table, _entity, cn);
            }

            if (InputModel.IsMixModel)
            {
                WriteChildData(_entity, cn);
            }
            return(true);
        }
Ejemplo n.º 5
0
        public bool WriteEntity(MD_InputEntity _entity, SqlConnection cn)
        {
            bool _ret = false;

            if (_entity.IsNewData)
            {
                _ret = WriteNewEntity(_entity, cn);
            }
            else
            {
                _ret = UpdateEntity(_entity, cn);
            }
            return(_ret);
        }
Ejemplo n.º 6
0
        public static bool CheckByRuleAssembly(Assembly _ruleAssmbly, MD_InputEntity _entity, ref Dictionary <string, string> ErrorList)
        {
            object     Class1 = _ruleAssmbly.CreateInstance("CheckRule");
            MethodInfo _minfo = Class1.GetType().GetMethod("Check");

            object[] _inputObj = new object[1];
            _inputObj[0] = _entity;
            string _ret = (string)_minfo.Invoke(Class1, _inputObj);

            if (_ret == "")
            {
                return(true);
            }
            ErrorList.Add(Guid.NewGuid().ToString(), _ret);
            return(false);
        }
Ejemplo n.º 7
0
        private void WriteChildData(MD_InputEntity _entity, SqlConnection cn)
        {
            foreach (MD_InputModel_Child _child in InputModel.ChildInputModel)
            {
                switch (_child.ChildModel.ModelType)
                {
                case "FORM":

                    break;

                case "GRID":
                    WriteGridChildData(_child, _entity.ChildInputData[_child.ID], cn);
                    break;
                }
            }
        }
Ejemplo n.º 8
0
 public void ChangeEntityData(MD_InputEntity DataEntity)
 {
     DataEntity.IsNewData = false;
     foreach (string _key in this.InputDict.Keys)
     {
         SinoUC_IM_Text _input = this.InputDict[_key];
         string         _val   = (_input.EditValue == null) ? null : _input.EditValue.ToString();
         if (DataEntity.InputData.ContainsKey(_key))
         {
             DataEntity.InputData[_key] = _val;
         }
         else
         {
             DataEntity.InputData.Add(_key, _val);
         }
     }
 }
Ejemplo n.º 9
0
        private string GetChildGridData(MD_InputModel_Child _child, MD_InputEntity entity)
        {
            List <MD_InputEntity> _ret = new List <MD_InputEntity>();

            List <MDQuery_GuideLineParameter> _callParam = new List <MDQuery_GuideLineParameter>();

            foreach (MD_InputModel_ChildParam _p in _child.Parameters)
            {
                string _pValue = ConvetDataByMainEntityData(_p.Value, entity);
                MDQuery_GuideLineParameter _cp = new MDQuery_GuideLineParameter(new MD_GuideLineParameter(_p.Name, "", _p.DataType, 0, 0, "", false, ""), _pValue);
                _callParam.Add(_cp);
            }

            DataTable _dt = QueryFactory.QueryGuideLine(_child.ChildModel.GetDataGuideLine, _callParam);

            return(_dt.DataTableToXml());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 将录入模型Add的实体数据转换为XML
        /// </summary>
        /// <param name="Entity"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public static string GetXMLDataByEntity(MD_InputEntity Entity)
        {
            DataTable dt = new DataTable("ResultTable");
            DataRow   dr = dt.NewRow();

            foreach (KeyValuePair <string, string> obj in Entity.InputData)
            {
                if (!string.IsNullOrEmpty(obj.Value.ToString()))
                {
                    dt.Columns.Add(obj.Key);
                    dr[obj.Key] = obj.Value;
                }
            }
            dt.Rows.Add(dr);
            System.IO.TextWriter tw = new System.IO.StringWriter();
            dt.WriteXml(tw);
            return(tw.ToString());
        }
Ejemplo n.º 11
0
        private string ConvetDataByMainEntityData(string valuestr, MD_InputEntity entity)
        {
            string _ret = valuestr;

            foreach (string _key in entity.InputData.Keys)
            {
                string _field    = string.Format("%{0}%", _key);
                object _valueObj = entity.InputData[_key];
                if (_valueObj != null)
                {
                    string _obj = _valueObj.ToString();
                    _ret = _ret.Replace(_field, _obj);
                }
                else
                {
                    _ret = _ret.Replace(_field, "");
                }
            }
            return(_ret);
        }
Ejemplo n.º 12
0
        public MD_InputEntity GetNewData(List <MDQuery_GuideLineParameter> Params)
        {
            MD_InputEntity _ret = new MD_InputEntity(InputModelName);

            if (InputModel.GetNewRecordGuideLine != "")
            {
                //执行取新数据指标
                List <MDQuery_GuideLineParameter> _callParam = (Params == null) ? new List <MDQuery_GuideLineParameter>() : Params;

                DataTable _dt = QueryFactory.QueryGuideLine(InputModel.GetNewRecordGuideLine, _callParam);
                _ret.IsNewData = true;
                if (_dt != null)
                {
                    _ret.InputData = GetInputDataByDataTable(_dt);
                }
            }
            else
            {
                //暂未实现
                //执行初始化指标
                //执行取数据指标
            }
            if (InputModel.IsMixModel)
            {
                _ret.ChildInputData = new Dictionary <string, string>();
                foreach (MD_InputModel_Child _child in InputModel.ChildInputModel)
                {
                    switch (_child.ChildModel.ModelType)
                    {
                    case "FORM":
                        //_ret.ChildInputData.Add(_child.ID, GetChildFormData(_child, _ret));
                        break;

                    case "GRID":
                        _ret.ChildInputData.Add(_child.ID, GetChildGridData(_child, _ret));
                        break;
                    }
                }
            }
            return(_ret);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 把数据列存到实体
        /// </summary>
        /// <param name="column"></param>
        /// <param name="entity"></param>
        /// <param name="sinoRequestUser"></param>
        private void SaveInputDataToEntityByColumns(MD_InputModel_Column column, MD_InputEntity entity, SinoRequestUser sinoRequestUser)
        {
            if (entity.InputData == null)
            {
                entity.InputData = new Dictionary <string, string>();
            }
            switch (column.ColumnType)
            {
            case "组织机构":
                //string orgCode = string.IsNullOrEmpty(HttpContext.Current.Request.Form[column.ColumnName]) ? "" : HttpContext.Current.Request.Form[column.ColumnName].ToString();
                string orgCode = string.IsNullOrEmpty("") ? "" : "".ToString();
                if (orgCode.Trim().IndexOf('[') > -1)
                {
                    string code = orgCode.Substring(orgCode.IndexOf('[') + 1, orgCode.IndexOf(']') - orgCode.IndexOf('[') - 1);
                    entity.InputData.Add(column.ColumnName, code);
                }
                else
                {
                    entity.InputData.Add(column.ColumnName, "");
                }
                break;

            case "代码表":
            case "移送管辖移往单位":
            case "派转移往单位":
                //string refCodeList = string.IsNullOrEmpty(HttpContext.Current.Request.Form[column.ColumnName]) ? "" : HttpContext.Current.Request.Form[column.ColumnName].ToString();
                string refCodeList = string.IsNullOrEmpty("") ? "" : "".ToString();
                //先判断是否为多选代码表,暂时判断只要不为空就为多选
                if (!string.IsNullOrEmpty(column.CanEditRule))
                {
                    if (refCodeList.Contains(','))
                    {
                        entity.InputData.Add(column.ColumnName, refCodeList);
                    }
                    else
                    {
                        string code = String.Empty;
                        if (refCodeList.Contains('['))
                        {
                            code = refCodeList.Substring(refCodeList.IndexOf('[') + 1, refCodeList.IndexOf(']') - refCodeList.IndexOf('[') - 1);
                        }
                        else
                        {
                            code = refCodeList;
                        }
                        entity.InputData.Add(column.ColumnName, code);
                    }
                }
                else
                {
                    if (refCodeList.Trim().IndexOf(',') > -1)
                    {
                        entity.InputData.Add(column.ColumnName, refCodeList);
                    }
                    else
                    {
                        if (refCodeList.Length > 1)
                        {
                            int temp = 0;
                            if (int.TryParse(refCodeList, out temp))
                            {
                                entity.InputData.Add(column.ColumnName, refCodeList);
                            }
                            else
                            {
                                string code = refCodeList.Substring(refCodeList.IndexOf('[') + 1, refCodeList.IndexOf(']') - refCodeList.IndexOf('[') - 1);
                                entity.InputData.Add(column.ColumnName, code);
                            }
                        }
                        else
                        {
                            entity.InputData.Add(column.ColumnName, "");
                        }
                    }
                }

                break;

            case "DATE":
            case "日期型":
                //if (!string.IsNullOrEmpty(HttpContext.Current.Request.Form[column.ColumnName]))
                if (!string.IsNullOrEmpty(""))
                {
                    //entity.InputData.Add(column.ColumnName, DateTime.Parse(HttpContext.Current.Request.Form[column.ColumnName]).ToString("s"));
                }
                break;

            case "RADIO":
                //string value = HttpContext.Current.Request.Form[column.ColumnName];
                string value = "";    //
                if (!string.IsNullOrEmpty(value))
                {
                    var array = value.Split(',');
                    entity.InputData.Add(column.ColumnName, array[0]);
                }
                break;

            case "VARCHAR":
            case "字符型":
            case "多行文本":
            case "NUMBER":
            case "数值型":
            case "目标单位":
                switch (column.EditFormat)
                {
                case "当前单位":
                    if (!string.IsNullOrEmpty(""))
                    {
                        //entity.InputData.Add(column.ColumnName, sinoRequestUser.BaseInfo.CurrentPost.PostDwId);
                    }
                    break;

                case "当前用户":
                    //if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["MenuId"]))
                    if (!string.IsNullOrEmpty(""))
                    {
                        entity.InputData.Add(column.ColumnName, sinoRequestUser.BaseInfo.UserId);
                    }
                    break;

                default:
                    if (column.EditFormat.ToUpper() == "HSBM")
                    {
                        //todo:还待处理HSBM保存时只保存HS编码
                        //string code = HttpContext.Current.Request.Form[column.ColumnName];
                        string code = "";
                        if (!string.IsNullOrEmpty(code))
                        {
                            if (code.IsDigit())
                            {
                                entity.InputData.Add(column.ColumnName, code);
                            }
                            else
                            {
                                try
                                {
                                    code = code.Substring(code.IndexOf('[') + 1, code.IndexOf(']') - code.IndexOf('[') - 1);
                                    entity.InputData.Add(column.ColumnName, code);
                                }
                                catch (Exception exception)
                                {
                                    string errorMessage = string.Format("HS编码[{0}]保存时格式异常{1}", code, exception.Message);
                                    //LogClient.WriteSystemLog(errorMessage, "ERROR");
                                }
                            }
                        }
                        else
                        {
                            entity.InputData.Add(column.ColumnName, "");
                        }
                    }
                    else if (column.EditFormat.ToUpper() == "PERSONLIST")
                    {
                        if (column.InputRule == "MutiSelect")
                        {
                            string tempText = "";        // HttpContext.Request.Form[column.ColumnName];

                            if (!string.IsNullOrEmpty(tempText))
                            {
                                if (tempText == column.ToolTipText)
                                {
                                    tempText = "";
                                }
                            }
                            entity.InputData.Add(column.ColumnName, tempText);
                        }
                        else
                        {
                            string userId = "";        // HttpContext.Current.Request.Form[column.ColumnName];
                            entity.InputData.Add(column.ColumnName, !string.IsNullOrEmpty(userId) ? userId : "");
                        }
                    }
                    else
                    {
                        string tempText = "";        // HttpContext.Current.Request.Form[column.ColumnName];

                        if (!string.IsNullOrEmpty(tempText))
                        {
                            if (tempText == column.ToolTipText)
                            {
                                tempText = "";
                            }
                        }
                        entity.InputData.Add(column.ColumnName, tempText);
                    }
                    break;
                }
                break;

            default:
                //entity.InputData.Add(column.ColumnName, (HttpContext.Current.Request.Form[column.ColumnName].LastIndexOf(',') == HttpContext.Current.Request.Form[column.ColumnName].Length - 1) ? HttpContext.Current.Request.Form[column.ColumnName].Substring(0, HttpContext.Current.Request.Form[column.ColumnName].Length - 1) : HttpContext.Current.Request.Form[column.ColumnName]);
                entity.InputData.Add(column.ColumnName, ("".LastIndexOf(',') == "".Length - 1) ? "".Substring(0, "".Length - 1) : "");
                break;
            }
        }
Ejemplo n.º 14
0
        public MD_InputEntity GetInputEntity(SinoRequestUser sinoRequestUser, ref string errorMessage, string confirm_parm)
        {
            string         formId                  = "aehyok";
            MD_InputEntity inputEntity             = new MD_InputEntity(formId);
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            //TODO 获取Form表单配置信息
            MD_InputModel inputModel = new MD_InputModel();             // GetInputModelByModelName();
            List <MD_InputModel_ColumnGroup> columnGroups = inputModel.Groups;

            if (columnGroups.Count > 0)
            {
                foreach (MD_InputModel_ColumnGroup group in columnGroups)
                {
                    if ((group.GroupType.ToUpper() != "QUERYMODEL") && (group.GroupType.ToUpper() != "APPREG"))
                    {
                        if (group.Columns != null)
                        {
                            foreach (MD_InputModel_Column mdColumn in group.Columns)
                            {
                                SaveInputDataToEntityByColumns(mdColumn, inputEntity, sinoRequestUser);
                                #region 代码表
                                if (mdColumn.ColumnType == "代码表")
                                {
                                    if (inputEntity.InputData.ContainsKey(mdColumn.ColumnName))
                                    {
                                        var inputCodeValue = inputEntity.InputData[mdColumn.ColumnName];
                                        if (string.IsNullOrWhiteSpace(inputCodeValue))                                        //如果取得得代码表值为空
                                        {
                                            if (mdColumn.Required)
                                            {
                                                AddErrorMessage(dictionary, mdColumn);
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            bool unlawful        = false;
                                            var  fullRefCodeData = new List <Object>();// SinoSZJS.Common.V2.Common.OraRefTableFactory.GetFullRefCodeData(mdColumn.EditFormat);
                                            #region 多选
                                            if (!string.IsNullOrEmpty(mdColumn.CanEditRule))
                                            {
                                                #region 输入值为多个
                                                if (inputCodeValue.IndexOf(",") > -1)
                                                {
                                                    var inputCodeValueArray = inputCodeValue.Split(',');

                                                    foreach (string str in inputCodeValueArray)
                                                    {
                                                        //if (fullRefCodeData.FindIndex(q => q.Code == str) == -1)
                                                        //{
                                                        //	unlawful = true;
                                                        //	break;
                                                        //}
                                                    }
                                                }
                                                #endregion

                                                #region 输入值为单个
                                                else
                                                {
                                                    //if (fullRefCodeData.FindIndex(q => q.Code == inputCodeValue) == -1)
                                                    //{
                                                    //	unlawful = true;
                                                    //}
                                                }
                                                #endregion
                                            }
                                            #endregion
                                            #region 单选
                                            else
                                            {
                                                //if (fullRefCodeData.FindIndex(q => q.Code == inputCodeValue) == -1)
                                                //{
                                                //	unlawful = true;
                                                //}
                                            }
                                            #endregion
                                            if (unlawful)
                                            {
                                                dictionary.Add(mdColumn.ColumnName, mdColumn.ColumnName + "");
                                                AddErrorMessage(dictionary, mdColumn);
                                                continue;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        AddErrorMessage(dictionary, mdColumn);
                                    }
                                }
                                #endregion
                                #region 必填项
                                if (mdColumn.Required)
                                {
                                    if (inputEntity.InputData.ContainsKey(mdColumn.ColumnName))
                                    {
                                        object value = inputEntity.InputData[mdColumn.ColumnName];
                                        if (value == null || value.ToString() == "")
                                        {
                                            AddErrorMessage(dictionary, mdColumn);
                                        }
                                        else
                                        {
                                            if (mdColumn.MaxInputLength > 0)
                                            {
                                                if (value.ToString().IsDigit() && value.ToString().Length > mdColumn.MaxInputLength)
                                                {
                                                    dictionary.Add(mdColumn.ColumnName, mdColumn.DisplayName + "输入的值非法!");
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        AddErrorMessage(dictionary, mdColumn);
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (MD_InputModel_Column md in inputModel.Columns)
                {
                    SaveInputDataToEntityByColumns(md, inputEntity, sinoRequestUser);
                }
            }
            //errorMessage = dictionary.Count > 0 ? string.Join("\n", dictionary.Values.ToArray()) : "";
            var    json  = JsonConvert.SerializeObject(dictionary, Formatting.Indented);
            string error = "";
            //根据confirm_parm参数 返回不同格式的errorMessage数据。
            //confirm_parm参数为1返回Common.Modal所需要的Json格式。
            //confirm_parm参数为2返回Common.alert所需要的string字符串格式。
            if (confirm_parm == "1")            //返回为Common.Modal  (Json格式)
            {
                errorMessage = dictionary.Count > 0 ? json : "";
            }
            else if (confirm_parm == "2")            //返回为Common.Alert  (string字符串)
            {
                foreach (var error_lst in dictionary)
                {
                    error += "" + error_lst.Value + "<br/>";
                }
                errorMessage = dictionary.Count > 0 ? error : "";
            }
            else            //如果不传confirm_parm参数1或者2,默认返回为Common.Modal (Json格式)。
            {
                errorMessage = dictionary.Count > 0 ? json : "";
            }
            return(inputEntity);
        }
Ejemplo n.º 15
0
        public Dictionary <string, string> GetNewChildRecord(MD_InputModel_Child _child, MD_InputEntity entity)
        {
            List <MDQuery_GuideLineParameter> _callParam = new List <MDQuery_GuideLineParameter>();

            foreach (MD_InputModel_ChildParam _p in _child.Parameters)
            {
                string _pValue = ConvetDataByMainEntityData(_p.Value, entity);
                MDQuery_GuideLineParameter _cp = new MDQuery_GuideLineParameter(new MD_GuideLineParameter(_p.Name, "", _p.DataType, 0, 0, "", false, ""), _pValue);
                _callParam.Add(_cp);
            }

            DataTable _dt = QueryFactory.QueryGuideLine(_child.ChildModel.GetNewRecordGuideLine, _callParam);

            return(GetInputDataByDataTable(_dt));
        }
Ejemplo n.º 16
0
        public bool CheckInputData(MD_InputEntity _entity, ref Dictionary <string, string> ErrorList)
        {
            ErrorList = new Dictionary <string, string>();
            bool _ret = true;

            if (InputModel == null)
            {
                return(true);
            }
            //必填项验证
            if (InputModel.Groups.Count > 0)
            {
                foreach (MD_InputModel_ColumnGroup _group in InputModel.Groups)
                {
                    foreach (MD_InputModel_Column _column in _group.Columns)
                    {
                        if (_column.Required)
                        {
                            if (_entity.InputData.ContainsKey(_column.ColumnName))
                            {
                                object _value = _entity.InputData[_column.ColumnName];
                                if (_value == null || _value.ToString() == "")
                                {
                                    AddErrorMsg(ErrorList, _column);
                                    _ret = false;
                                }
                            }
                            else
                            {
                                AddErrorMsg(ErrorList, _column);
                                _ret = false;
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (MD_InputModel_Column _column in InputModel.Columns)
                {
                    if (_column.Required)
                    {
                        if (_entity.InputData.ContainsKey(_column.ColumnName))
                        {
                            object _value = _entity.InputData[_column.ColumnName];
                            if (_value == null || _value.ToString() == "")
                            {
                                AddErrorMsg(ErrorList, _column);
                                _ret = false;
                            }
                        }
                        else
                        {
                            AddErrorMsg(ErrorList, _column);
                            _ret = false;
                        }
                    }
                }
            }
            if (!_ret)
            {
                return(_ret);
            }

            //foreach (Assembly _ruleAssmbly in InputModel.RuleAssemblys)
            //{
            //        bool _cret = InputModelRuleBuilder.CheckByRuleAssembly(_ruleAssmbly, _entity, ref ErrorList);
            //}
            if (ErrorList.Count > 0)
            {
                _ret = false;
            }

            return(_ret);
        }
Ejemplo n.º 17
0
 private MD_InputEntity GetChildFormData(MD_InputModel_Child _child, MD_InputEntity entity)
 {
     return(new MD_InputEntity());
 }
Ejemplo n.º 18
0
        private void WriteNewTableData(MD_InputModel_SaveTable _table, MD_InputEntity _entity, SqlConnection cn)
        {
            StringBuilder _vStr = new StringBuilder();

            _vStr.Append(" values ( ");
            StringBuilder _sb = new StringBuilder();

            _sb.Append("insert into ");
            _sb.Append(_table.TableName);
            _sb.Append("  ( ");
            string _fg = "";

            foreach (MD_InputModel_SaveTableColumn _col in _table.Columns)
            {
                if (_col.SrcColumn == "" && _col.Method == "")
                {
                    //如果写入源字段和算法都为空,则此字段不写入
                    continue;
                }
                _sb.Append(string.Format("{0}{1}", _fg, _col.DesColumn));
                if (_col.SrcColumn == "")
                {
                    // 如果写入源字段为空,则仅使用算法写入本字段内容
                    _vStr.Append(_fg);
                    _vStr.Append(ConvertVar(_col.Method, _entity));
                }
                else
                {
                    //如果写入源字段不为空
                    if (_col.Method == "")
                    {
                        //如果算法为空,则写入源字段内容
                        _vStr.Append(string.Format("{0}:{1}", _fg, _col.DesColumn));
                    }
                    else
                    {
                        //算法不为空,将算法做为写入算法,参数照样代入
                        _vStr.Append(_fg);
                        _vStr.Append(string.Format(_col.Method, ConvertVar(_col.Method, _entity)));
                    }
                }
                _fg = ",";
            }

            _sb.Append(" ) ");
            _sb.Append(_vStr.ToString());
            _sb.Append(" ) ");

            List <SqlParameter> _plist = new List <SqlParameter>();

            foreach (MD_InputModel_SaveTableColumn _col in _table.Columns)
            {
                string _cname = _col.SrcColumn;
                if (_cname != "")
                {
                    string _data = _entity.InputData.ContainsKey(_cname) ? _entity.InputData[_cname] : null;
                    _plist.Add(new SqlParameter(string.Format(":{0}", _col.DesColumn), _data));
                }
            }
            SqlParameter[] _params = _plist.ToArray();
            SqlHelper.ExecuteNonQuery(cn, CommandType.Text, _sb.ToString(), _params);
        }
Ejemplo n.º 19
0
        private void UpdateTableData(MD_InputModel_SaveTable _table, MD_InputEntity _entity, SqlConnection cn)
        {
            List <string> _mainKeyList = MetaDataFactory.GetDBPrimayKeyList(_table.TableName);

            StringBuilder _sb = new StringBuilder();

            _sb.Append("update  ");
            _sb.Append(_table.TableName);
            _sb.Append(" set  ");
            string _fg = "";
            //制作更新字段SQL语句
            int _UpdateFieldCount = 0;

            foreach (MD_InputModel_SaveTableColumn _col in _table.Columns)
            {
                if (_col.SrcColumn == "" && _col.Method == "")
                {
                    //如果写入源字段和算法都为空,则此字段不写入
                    continue;
                }
                if (!_mainKeyList.Contains(_col.DesColumn))
                {
                    _UpdateFieldCount++;
                    _sb.Append(_fg);
                    _fg = " , ";
                    _sb.Append(_col.DesColumn);
                    if (_col.SrcColumn == "")
                    {
                        _sb.Append("=");
                        _sb.Append(ConvertVar(_col.Method, _entity));
                    }
                    else
                    {
                        if (_col.Method == "")
                        {
                            _sb.Append("=:");
                            _sb.Append(_col.DesColumn);
                        }
                        else
                        {
                            _sb.Append("=");
                            _sb.Append(string.Format(_col.Method, ConvertVar(_col.Method, _entity)));
                        }
                    }
                }
            }
            if (_UpdateFieldCount < 1)
            {
                //无更新字段,直接返回true;
                return;
            }
            _sb.Append(" where ");
            _fg = "";
            //制作主键字段条件语句
            foreach (string _key in _mainKeyList)
            {
                _sb.Append(_fg);
                _sb.Append(_key);
                _sb.Append(" =:");
                _sb.Append(_key);
                _fg = " and ";
            }

            SqlCommand _cmd = new SqlCommand(_sb.ToString(), cn);

            //添加更新字段参数
            foreach (MD_InputModel_SaveTableColumn _col in _table.Columns)
            {
                string _cname = _col.SrcColumn;
                if (_cname != "")
                {
                    string _data = _entity.InputData.ContainsKey(_cname) ? _entity.InputData[_cname] : null;
                    if (!_mainKeyList.Contains(_col.DesColumn))
                    {
                        _cmd.Parameters.Add(string.Format(":{0}", _col.DesColumn), _data);
                    }
                }
            }
            //添加主键字段参数
            foreach (string _key in _mainKeyList)
            {
                MD_InputModel_SaveTableColumn _kcol = GetColumnByDesName(_key, _table.Columns);
                if (_kcol != null)
                {
                    string _data = _entity.InputData.ContainsKey(_kcol.SrcColumn) ? _entity.InputData[_kcol.SrcColumn] : null;
                    _cmd.Parameters.Add(string.Format(":{0}", _key), _data);
                }
            }
            _cmd.ExecuteNonQuery();
        }