Пример #1
0
        public int UpdateOne(XModel setsModel)
        {
            string sSql = UpdateOneSql(setsModel);

            if (String.IsNullOrEmpty(sSql))
            {
                if (System.Configuration.ConfigurationManager.AppSettings["ReturnValueWhenUpdateEmpty"] != null)
                {
                    return(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ReturnValueWhenUpdateEmpty"]));
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                int iR = this.Execute(sSql);
                if (iR == 1)
                {
                    setsModel.ClearAllUpdated();
                }
                return(iR);
            }
        }
Пример #2
0
        public int Insert(XModel insertModel, bool returnIdentityID)
        {
            string sSql = this.InsertSql(insertModel);
            int    iR;

            if (string.IsNullOrEmpty(sSql))
            {
                return(-1);
            }
            if (returnIdentityID)
            {
                sSql = sSql + ";SELECT @@IDENTITY";
            }
            if (!returnIdentityID)
            {
                iR = this.Execute(sSql);
            }
            else
            {
                iR = Convert.ToInt32(this.GetValue(sSql));
            }

            if (iR > 0)
            {
                insertModel.ClearAllUpdated();
            }
            return(iR);
        }
Пример #3
0
 ///**************************************************************
 ///outputModel
 ///关键值未赋,称为状态A=未初始化状态;
 ///关键值已赋,但其它值未赋,称为状态B=已初始化状态;
 ///所有值已经赋为为C=完整状态
 ///当keyValues为空时,则outputModel不能为未初始化状态。
 public void LoadFromDataRow(XModel outputModel, DataRow drCache)
 {
     if (drCache != null)
     {
         XModel xdm = outputModel;
         for (int i = 0; i < xdm.Fields.Count; i++)
         {
             string fname = xdm.Fields[i].name;
             if (drCache.Table.Columns.Contains(fname))
             {
                 xdm.Fields[i].value = drCache[fname];
             }
         }
         xdm.LoadSucceed = true;
         outputModel.ClearAllUpdated();
     }
 }
Пример #4
0
        ///**************************************************************
        public int SaveToDb(XModel updateModel)
        {
            _CheckKeyField();
            string sets       = updateModel.SetsListString();
            string fieldLists = updateModel.FieldsListStringForInsert(false);
            string valueLists = updateModel.ValuesListStringForInsert(false);
            //string whereStr=updateModel.DefaultConditionString(this.KeyField);
            string whereStr = GetKeyConditionString(false, updateModel);
            //if (string.IsNullOrEmpty(sets))
            //{
            //    return 0;
            //}
            string sSql_Exists = "Select * from  " + this.TableName + " where " + whereStr;
            string sSql_Update = String.IsNullOrEmpty(sets) ? "Select 1;" : "Update " + this.TableName + " set " + sets + " where " + whereStr + ";";
            string sSql_Insert = String.IsNullOrEmpty(fieldLists) || String.IsNullOrEmpty(valueLists) ? "Select 1;" : "Insert into " + this.TableName + "(" + fieldLists + ") values(" + valueLists + ");";
            string sSql        = String.Format("if exists({0}) {1} else {2}", sSql_Exists, sSql_Update, sSql_Insert);
            int    iR          = 0;

            ULCode.QDA.ProviderType ct = XSql.GetDB(this.CnName).GetProviderType();
            if (ct == ProviderType.MsSql)
            {
                iR = this.Execute(sSql);
            }
            else// if (ct == ProviderType.OleDb)
            {
                if (XSql.IsHasRow(this.CnName, sSql_Exists))
                {
                    iR = this.Execute(sSql_Update);
                }
                else
                {
                    iR = this.Execute(sSql_Insert);
                }
            }
            if (iR > 0)
            {
                updateModel.ClearAllUpdated();
            }
            return(iR);
        }