示例#1
0
 /// <summary>
 /// 删除记录对象
 /// </summary>
 /// <returns></returns>
 internal int Delete()
 {
     try
     {
         if (this.Connection == null)
         {
             OnException(@"请为数据记录指定数据库连接对象。");
             return(ERROR);
         }
         List <string> pName  = new List <string>();
         List <object> pValue = new List <object>();
         string        sql    = "";
         if (this.Connection.ConnectionType == DBType.SQLServer)
         {
             sql = new SQLGeneral().General(this, ExecuteMode.Delete);
         }
         else
         {
             sql = new SQLGeneral().General(this, ExecuteMode.Delete, out pName, out pValue);
         }
         Command cmd = new Command(this.Connection);
         cmd.OnExceptionEx += new ExceptionExHandler(cmd_OnExceptionEx);
         cmd.OnException   += new ExceptionHandler(cmd_OnException);
         doflag             = 0;
         return(cmd.Execute(sql, pName.ToArray(), pValue.ToArray()));
     }
     catch (Exception ex)
     {
         OnException(ex.ToString());
         return(ERROR);
     }
 }
示例#2
0
        internal int InsertOrUpdate()
        {
            try
            {
                if (this.Connection == null)
                {
                    OnException(@"请为数据记录指定数据库连接对象。");
                    return(ERROR);
                }

                string sqlChk = new SQLGeneral().General(this, ExecuteMode.Check);
                //OnException(@"检查主键sql。" + sqlChk);
                Command cmd = new Command(this.Connection);
                cmd.OnException   += new ExceptionHandler(cmd_OnException);
                cmd.OnExceptionEx += new ExceptionExHandler(cmd_OnExceptionEx);
                DataTable dtCount = cmd.GetDataTable(sqlChk);
                if (dtCount == null)
                {
                    return(ERROR);
                }
                bool          bUpdate    = Convert.ToBoolean(dtCount.Rows[0][0]);
                List <string> pName      = new List <string>();
                List <object> pValue     = new List <object>();
                string        sqlExecute = string.Empty;
                if (bUpdate)
                {
                    doflag = 3;
                    if (this.Connection.ConnectionType == DBType.SQLServer)
                    {
                        sqlExecute = new SQLGeneral().General(this, ExecuteMode.Update);
                    }
                    else
                    {
                        sqlExecute = new SQLGeneral().General(this, ExecuteMode.Update, out pName, out pValue);
                    }
                }
                else
                {
                    doflag = 1;
                    if ((DBType)this.Connection.ConnectionType == DBType.SQLServer)
                    {
                        sqlExecute = new SQLGeneral().General(this, ExecuteMode.Insert);
                    }
                    else
                    {
                        sqlExecute = new SQLGeneral().General(this, ExecuteMode.Insert, out pName, out pValue);
                    }

                    this._IsNewRecord = false;
                }
                return(cmd.Execute(sqlExecute, pName.ToArray(), pValue.ToArray()));
            }
            catch (Exception ex)
            {
                OnException(ex.ToString());
                return(ERROR);
            }
        }
示例#3
0
 /// <summary>
 /// 插入新的记录
 /// </summary>
 /// <returns></returns>
 internal int Insert()
 {
     try
     {
         if (this.Connection == null)
         {
             OnException(@"请为数据记录指定数据库连接对象。");
             return(ERROR);
         }
         List <string> pName  = new List <string>();
         List <object> pValue = new List <object>();
         string        sql    = "";
         if (this.Connection.ConnectionType == DBType.SQLServer)
         {
             sql = new SQLGeneral().General(this, ExecuteMode.Insert);
         }
         else
         {
             sql = new SQLGeneral().General(this, ExecuteMode.Insert, out pName, out pValue);
         }
         Command cmd = new Command(this.Connection);
         cmd.OnExceptionEx += new ExceptionExHandler(cmd_OnExceptionEx);
         cmd.OnException   += new ExceptionHandler(cmd_OnException);
         doflag             = 1;
         this._IsNewRecord  = false;
         object[] values = pValue.ToArray();
         string   vals   = string.Empty;
         foreach (object obj in values)
         {
             vals += string.Format(@"'{0}',", obj.ToString());
         }
         //File.WriteAllText(@"log.log", sql + vals);
         return(cmd.Execute(sql, pName.ToArray(), pValue.ToArray()));
     }
     catch (Exception ex)
     {
         OnException(ex.ToString());
         return(ERROR);
     }
 }