Beispiel #1
0
 protected abstract bool DeleteData(IUpatedataInfo DataRow);
Beispiel #2
0
        protected override bool SaveData(IUpatedataInfo DataRow)
        {
            string table = DataRow.TableName;

            if (string.IsNullOrEmpty(table))
            {
                return(false);
            }
            string idStr = DataRow.IdentifyField;

            if (string.IsNullOrEmpty(idStr))
            {
                return(false);
            }
            List <string> fields = DataRow.GetUpateFields();

            if (fields.Count == 0)
            {
                return(false);
            }

            using (var cmd = Command())
            {
                bool   isNew;
                object t = DataRow.GetValueByName(idStr);
                isNew = t == null || t == DBNull.Value || (int)t <= 0;

                SqlParameter ptr;
                string       sql1 = string.Empty, sql2 = string.Empty;

                foreach (string f in fields)
                {
                    if (f == idStr)
                    {
                        continue;
                    }
                    var val = DataRow.GetValueByName(f);
                    if (val == null)
                    {
                        val = DBNull.Value;
                    }
                    ptr = new SqlParameter("@" + f, val);
                    cmd.Parameters.Add(ptr);
                    if (isNew)
                    {
                        sql1 += ",[" + f + "]";
                        sql2 += ",@" + f;
                    }
                    else
                    {
                        sql1 += ",[" + f + "]=@" + f;
                    }
                }
                if (!string.IsNullOrEmpty(sql1))
                {
                    sql1 = sql1.Substring(1);
                }
                string sql;
                if (isNew)
                {
                    sql = "insert into [" + table + "](" + sql1 + ") values(" + sql2.Substring(1) + ")";
                }
                else
                {
                    sql = "update [" + table + "] set " + sql1 + " where [" + idStr + "]=@" + idStr;
                    ptr = new SqlParameter("@" + idStr, DataRow.GetValueByName(idStr));
                    cmd.Parameters.Add(ptr);
                }

                cmd.CommandText = sql;
                TimerStart();
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    Shotgun.Library.ErrLogRecorder.SqlError(ex, sql, cmd.Parameters);
                    cmd.Dispose();
                    throw;
                }
                finally
                {
                    TimerEnd(sql);
                }

                if (isNew)
                {
                    cmd.CommandText = "select @@identity";
                    t = cmd.ExecuteScalar();
                }
                else
                {
                    t = null;
                }
                cmd.Dispose();

                DataRow.SetUpdated(t);
            }
            return(true);
        }
Beispiel #3
0
 protected abstract bool SaveData(IUpatedataInfo DataRow);
Beispiel #4
0
 bool IBaseDataClass2.DeleteData(IUpatedataInfo DataRow)
 {
     return(DeleteData(DataRow));
 }
Beispiel #5
0
 bool IBaseDataClass2.SaveData(IUpatedataInfo DataRow)
 {
     return(SaveData(DataRow));
 }
Beispiel #6
0
 protected override bool DeleteData(IUpatedataInfo DataRow)
 {
     return((bool)getMethond("DeleteData").Invoke(_db, new object[] { DataRow }));
 }
Beispiel #7
0
 protected override bool DeleteData(IUpatedataInfo DataRow)
 {
     throw new NotImplementedException();
 }