public long GetMaxID()
 {
     try
     {
         DataSet ds = new DataSet();
         stm = string.Format("SELECT TOP 1 * FROM {0} ORDER BY VIS_ID DESC", _tbName);
         DbCallback.SetCommandText(stm);
         ds = DbCallback.ExecuteToDataSet();
         if (ds != null)
         {
             if (ds.Tables != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     if (0 < ds.Tables[0].Rows.Count)
                     {
                         if (!DBNull.Value.Equals(ds.Tables[0].Rows[0]["VIS_ID"]))
                         {
                             return((long)ds.Tables[0].Rows[0]["VIS_ID"]);
                         }
                     }
                 }
             }
         }
         throw new Exception("Get maximum id failed!");
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
        public bool CheckCarTag(string cardId)
        {
            DataSet ds = new DataSet();

            try
            {
                stm = "SELECT * FROM tbOperator WHERE CarTag=@CarTag AND IsActive='ACTIVE'";
                DbCallback.SetCommandText(stm);
                DbCallback.AddInputParameter("@CarTag", SqlDbType.NVarChar, cardId);
                ds = DbCallback.ExecuteToDataSet();
                if (ds != null)
                {
                    if (ds.Tables != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows != null)
                            {
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }
 public DataTable Select(long vis_id)
 {
     try
     {
         DataSet ds = new DataSet();
         stm = string.Format("SELECT * FROM {0} WHERE VIS_ID=@VIS_ID", _tbName);
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@VIS_ID", SqlDbType.BigInt, vis_id);
         ds = DbCallback.ExecuteToDataSet();
         if (ds != null)
         {
             if (ds.Tables != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     return(ds.Tables[0]);
                 }
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
        public DataTable GetData(string cardId)
        {
            DataSet ds = new DataSet();

            try
            {
                stm = "SELECT [OID] AS [ID], [RFIDCode] AS [RFID],[CarTag] AS [ทะเบียนรถ],[CreatedDate] AS [วันที่บันทึก],[ExpiryDate] AS [วันที่หมดอายุ],[IsActive] AS [สถานะ] FROM tbOperator WHERE RFIDCode=@RFIDCode";
                DbCallback.SetCommandText(stm);
                DbCallback.AddInputParameter("@RFIDCode", SqlDbType.NVarChar, cardId);
                ds = DbCallback.ExecuteToDataSet();
                if (ds != null)
                {
                    if (ds.Tables != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows != null)
                            {
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    return(ds.Tables[0]);
                                }
                            }
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }
 public string GetCharValue(string name)
 {
     try
     {
         DataSet ds = new DataSet();
         stm = "SELECT * FROM tbConfig WHERE Name=@Name";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@Name", SqlDbType.NVarChar, name);
         ds = DbCallback.ExecuteToDataSet();
         if (ds != null)
         {
             if (ds.Tables != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     if (ds.Tables[0].Rows != null)
                     {
                         if (ds.Tables[0].Rows.Count > 0)
                         {
                             return((string)(ds.Tables[0].Rows[0]["CharVal"]));
                         }
                     }
                 }
             }
         }
         return(string.Empty);
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
 public void DeactivateUser(string userName)
 {
     try
     {
         stm = "UPDATE tbUser SET IsActive='N' WHERE UserName=@UserName";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@UserName", SqlDbType.NVarChar, userName);
         DbCallback.ExecuteNonQuery();
     }
     catch (Exception ex) { throw ex; }
 }
        public void ActivateUser(string userName, DateTime expireDate)
        {
            try
            {
                if (expireDate == null)
                {
                    stm = "UPDATE tbUser SET IsActive='Y' WHERE UserName=@UserName";
                    DbCallback.SetCommandText(stm);
                    DbCallback.AddInputParameter("@UserName", SqlDbType.NVarChar, userName);
                    DbCallback.ExecuteNonQuery();
                }
                else
                {
                    Exception      _ex1 = null;
                    SqlTransaction tx;
                    SqlConnection  conn = new SqlConnection();
                    conn.ConnectionString = DbCallback.ConnectionString;
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    conn.Open();
                    tx = conn.BeginTransaction();
                    try
                    {
                        stm = "UPDATE tbUser SET IsActive1='Y', ExpireDate=@ExpireDate WHERE UserName=@UserName";
                        DbCallback.SetCommandText(stm);
                        DbCallback.AddInputParameter("@UserName", SqlDbType.NVarChar, userName);
                        DbCallback.AddInputParameter("@ExpireDate", SqlDbType.DateTime, expireDate);
                        DbCallback.ExecuteNonQuery(conn, tx);

                        tx.Commit();
                    }
                    catch (Exception ex1)
                    {
                        tx.Rollback();
                        _ex1 = ex1;
                    }
                    conn.Close();
                    if (_ex1 != null)
                    {
                        throw _ex1;
                    }
                }
            }
            catch (Exception ex) { throw ex; }
        }
 public void AddAdmin(string userName, string pwd, int iAuth, bool isActive, string rfid, DateTime expireDate, string comment)
 {
     try
     {
         stm = "INSERT INTO tbUser (UserName, Password, Auth, IsActive, RFID, ExpireDate, Comment, CreateDate) VALUES (@UserName, @Password, @Auth, @IsActive, @RFID, @ExpireDate, @Comment, GETDATE())";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@UserName", SqlDbType.NVarChar, userName);
         DbCallback.AddInputParameter("@Password", SqlDbType.NVarChar, pwd);
         DbCallback.AddInputParameter("@Auth", SqlDbType.Int, iAuth);
         DbCallback.AddInputParameter("@IsActive", SqlDbType.NVarChar, isActive);
         DbCallback.AddInputParameter("@RFID", SqlDbType.NVarChar, rfid);
         DbCallback.AddInputParameter("@ExpireDate", SqlDbType.DateTime, expireDate);
         DbCallback.AddInputParameter("@Comment", SqlDbType.NVarChar, comment);
         DbCallback.ExecuteNonQuery();
     }
     catch (Exception ex) { throw ex; }
 }
 public int SetCharValue(string name, string value, string description)
 {
     try
     {
         DataSet ds = new DataSet();
         stm = "UPDATE tbConfig SET CharVal=@CharVal, Description=@Description WHERE Name=@Name";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@Name", SqlDbType.NVarChar, name);
         DbCallback.AddInputParameter("@CharVal", SqlDbType.NVarChar, value);
         DbCallback.AddInputParameter("@Description", SqlDbType.NVarChar, description);
         return(DbCallback.ExecuteNonQuery());
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
 public bool Insert(DataRow dr, out int resCode, out string resDesc)
 {
     try
     {
         //"INSERT INTO tbUser (UserName, Password, Auth, IsActive, RFID, ExpireDate, Comment, CreateDate) VALUES (@UserName, @Password, @Auth, @IsActive, @RFID, @ExpireDate, @Comment, GETDATE())";
         stm = "INSERT INTO tbOperator (RFIDCode, CarTag, CarDescription, CreatedDate, ExpiryDate, IsActive, Comment) VALUES (@RFIDCode, @CarTag, @CarDescription, GETDATE(), @ExpiryDate, @IsActive, @Comment)";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@RFIDCode", SqlDbType.NVarChar, dr["RFIDCode"]);
         DbCallback.AddInputParameter("@CarTag", SqlDbType.NVarChar, dr["CarTag"]);
         DbCallback.AddInputParameter("@CarDescription", SqlDbType.NVarChar, dr["CarDescription"]);
         DbCallback.AddInputParameter("@ExpiryDate", SqlDbType.Date, dr["ExpiryDate"]);
         DbCallback.AddInputParameter("@IsActive", SqlDbType.NVarChar, dr["IsActive"]);
         DbCallback.AddInputParameter("@Comment", SqlDbType.NVarChar, dr["Comment"]);
         DbCallback.ExecuteNonQuery();
         resCode = 0;
         resDesc = "DONE Insertion.";
         return(true);
     }
     catch (Exception ex) { resCode = -99; resDesc = ex.Message; return(false); }
 }
        public DataSet GetBO23(string carTag)
        {
            DataSet ds = new DataSet();

            try
            {
                //stm = "SELECT TOP 100 [BO23],[BoDate] AS [วันที่],[B_Type] AS [ชนิด],[B_Name] AS [ชื่อชนิด],[B_Number] AS [จำนวน] FROM tbBo23Test ";
                //stm += "WHERE CarTag=@CarTag";
                stm  = "SELECT TOP 100 * FROM tbBo23Test ";
                stm += "WHERE CarTag=@CarTag";
                DbCallback.SetCommandText(stm);
                DbCallback.AddInputParameter("@CarTag", SqlDbType.NVarChar, carTag);
                return(DbCallback.ExecuteToDataSet());
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }
 public void ChangePassword(string userName, string oldPwd, string newPwd)
 {
     try
     {
         int currentAuth;
         if (!Login(userName, oldPwd, out currentAuth))
         {
             throw new Exception("ไม่สามารถบันทึกรหัสผ่านใหม่ได้! เนื่องจากชื่อผู้ใช้ไม่ถูกต้องหรือรหัสผ่านเดิมไม่ถูกต้อง");
         }
         else
         {
             stm = "UPDATE tbUser SET Password=@Password WHERE UserName=@UserName";
             DbCallback.SetCommandText(stm);
             DbCallback.AddInputParameter("@UserName", SqlDbType.NVarChar, userName);
             DbCallback.AddInputParameter("@Password", SqlDbType.NVarChar, newPwd);
             DbCallback.ExecuteNonQuery();
         }
     }
     catch (Exception ex) { throw ex; }
 }
 public bool Update(DataRow dr, out int resCode, out string resDesc)
 {
     try
     {
         stm = "UPDATE tbOperator SET RFIDCode=@RFIDCode, CarTag=@CarTag, CarDescription=@CarDescription, CreatedDate=@CreatedDate, ExpiryDate=@ExpiryDate, IsActive=@IsActive, Comment=@Comment WHERE OID=@OID";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@OID", SqlDbType.UniqueIdentifier, dr["OID"]);
         DbCallback.AddInputParameter("@RFIDCode", SqlDbType.NVarChar, dr["RFIDCode"]);
         DbCallback.AddInputParameter("@CarTag", SqlDbType.NVarChar, dr["CarTag"]);
         DbCallback.AddInputParameter("@CarDescription", SqlDbType.NVarChar, dr["CarDescription"]);
         DbCallback.AddInputParameter("@CreatedDate", SqlDbType.Date, dr["CreatedDate"]);
         DbCallback.AddInputParameter("@ExpiryDate", SqlDbType.Date, dr["ExpiryDate"]);
         DbCallback.AddInputParameter("@IsActive", SqlDbType.NVarChar, dr["IsActive"]);
         DbCallback.AddInputParameter("@Comment", SqlDbType.NVarChar, dr["Comment"]);
         DbCallback.ExecuteNonQuery();
         resCode = 0;
         resDesc = "DONE Update.";
         return(true);
     }
     catch (Exception ex) { resCode = -99; resDesc = ex.Message; return(false); }
 }
Exemple #14
0
 public int Insert(long visID, long journalID, string bType, string face)
 {
     try
     {
         DataSet ds = new DataSet();
         stm = string.Format("INSERT INTO {0} (VIS_ID, TimeText, JournalID, B_TYPE, FACE, STATE_ID) VALUES (@VIS_ID, @TimeText, @JournalID, @B_TYPE, @FACE, @STATE_ID)", _tbName);
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@VIS_ID", SqlDbType.BigInt, visID);
         DbCallback.AddInputParameter("@TimeText", SqlDbType.NVarChar, DateTime.Now.ToString("yyyy-MM-dd, HH:mm:ss"));
         DbCallback.AddInputParameter("@JournalID", SqlDbType.BigInt, journalID);
         DbCallback.AddInputParameter("@B_TYPE", SqlDbType.NVarChar, bType);
         DbCallback.AddInputParameter("@FACE", SqlDbType.NVarChar, face);
         DbCallback.AddInputParameter("@STATE_ID", SqlDbType.Int, 0);
         return(DbCallback.ExecuteNonQuery());
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
Exemple #15
0
 public int Update(long vis_id, int state_id, string job, float score1, float score2, float score3, float score4, string runStatus)
 {
     try
     {
         DataSet ds = new DataSet();
         stm = string.Format("UPDATE {0} SET STATE_ID=@STATE_ID, {1}_SCORE1=@SCORE1, {1}_SCORE2=@SCORE2, {1}_SCORE3=@SCORE3, {1}_SCORE4=@SCORE4, {1}_RUN_STATUS=@RUN_STATUS WHERE VIS_ID=@VIS_ID", _tbName, job);
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@VIS_ID", SqlDbType.BigInt, vis_id);
         DbCallback.AddInputParameter("@STATE_ID", SqlDbType.Int, state_id);
         DbCallback.AddInputParameter("@SCORE1", SqlDbType.Float, score1);
         DbCallback.AddInputParameter("@SCORE2", SqlDbType.Float, score2);
         DbCallback.AddInputParameter("@SCORE3", SqlDbType.Float, score3);
         DbCallback.AddInputParameter("@SCORE4", SqlDbType.Float, score4);
         DbCallback.AddInputParameter("@RUN_STATUS", SqlDbType.NVarChar, runStatus);
         return(DbCallback.ExecuteNonQuery());
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
Exemple #16
0
 public void GetData(int id, out string message, out int number)
 {
     {
         message = "NG";
         number  = 0;
     }
     try
     {
         DataSet ds = new DataSet();
         stm = "SELECT * FROM tbVisionTest WHERE ID=@ID";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@ID", SqlDbType.NVarChar, id);
         ds = DbCallback.ExecuteToDataSet();
         if (ds != null)
         {
             if (ds.Tables != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     if (ds.Tables[0].Rows != null)
                     {
                         if (ds.Tables[0].Rows.Count > 0)
                         {
                             message = (string)(ds.Tables[0].Rows[0]["Message"]);
                             try { number = (int)(ds.Tables[0].Rows[0]["GoodBasket"]); }
                             catch { number = 0; }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
        public bool GetCarTag(string cardId, out string carTag)
        {
            DataSet ds = new DataSet();

            try
            {
                stm = "SELECT * FROM tbOperator WHERE RFIDCode=@RFIDCode AND IsActive='ACTIVE'";
                DbCallback.SetCommandText(stm);
                DbCallback.AddInputParameter("@RFIDCode", SqlDbType.NVarChar, cardId);
                ds = DbCallback.ExecuteToDataSet();
                if (ds != null)
                {
                    if (ds.Tables != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows != null)
                            {
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    carTag = Convert.ToString(ds.Tables[0].Rows[0]["CarTag"]);
                                    return(true);
                                }
                            }
                        }
                    }
                }
                carTag = string.Empty;
                return(false);
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }
 public long GetIntValue(string name)
 {
     try
     {
         DataSet ds = new DataSet();
         stm = "SELECT * FROM tbConfig WHERE Name=@Name";
         DbCallback.SetCommandText(stm);
         DbCallback.AddInputParameter("@Name", SqlDbType.NVarChar, name);
         ds = DbCallback.ExecuteToDataSet();
         if (ds != null)
         {
             if (ds.Tables != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     if (ds.Tables[0].Rows != null)
                     {
                         if (ds.Tables[0].Rows.Count > 0)
                         {
                             if (!DBNull.Value.Equals(ds.Tables[0].Rows[0]["IntVal"]))
                             {
                                 return(Convert.ToInt32(ds.Tables[0].Rows[0]["IntVal"]));
                             }
                         }
                     }
                 }
             }
         }
         throw new Exception("GetIntValue error!");
     }
     catch (Exception ex)
     {
         DbCallback.CloseConnection();
         throw ex;
     }
 }
        public bool Login(string userName, string pwd, out int currentAuthentication)
        {
            try
            {
                stm = "SELECT * FROM tbUser WHERE (UserName=@UserName) AND (Password=@Password) AND (IsActive='Y')";

                DbCallback.SetCommandText(stm);
                DbCallback.AddInputParameter("@UserName", SqlDbType.NVarChar, userName);
                DbCallback.AddInputParameter("@Password", SqlDbType.NVarChar, pwd);
                DataSet ds = DbCallback.ExecuteToDataSet();
                if (ds != null)
                {
                    if (ds.Tables != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows != null)
                            {
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    currentAuthentication = Convert.ToInt32(ds.Tables[0].Rows[0]["Auth"]);
                                    return(true);
                                }
                            }
                        }
                    }
                }
                currentAuthentication = 0;
                return(false);
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }
Exemple #20
0
        public void ExecuteNonQuery(string sprocName, ref List <SaveStructure> e)
        {
            // ------------------------------------------------
            // Transaction loop
            // ------------------------------------------------
            SqlConnection conn = new SqlConnection(DbCallback.ConnectionString);

            conn.Open();
            SqlTransaction tx        = conn.BeginTransaction();
            bool           CatchFlag = false;
            Exception      _ex;

            try
            {
                for (int i = 0; i < e.Count; i++)
                {
                    SaveStructure arg = e[i];

                    // ------------------------------------------------
                    // Initialize return value
                    // ------------------------------------------------
                    arg.ReturnValue = -99;

                    // ------------------------------------------------
                    // Stroe procedure name
                    // ------------------------------------------------
                    DbCallback.SetCommandStoredProcedure(sprocName);

                    // ------------------------------------------------
                    // Input parameters
                    // ------------------------------------------------
                    if (arg.Inputs != null)
                    {
                        foreach (KeyValuePair <string, ParameterStructure> input in arg.Inputs)
                        {
                            DbCallback.AddInputParameter(input.Value.Name, input.Value.sqlDbType, input.Value.dbValue);
                        }
                    }

                    // ------------------------------------------------
                    // Output parameters
                    // ------------------------------------------------
                    if (arg.Output != null)
                    {
                        foreach (KeyValuePair <string, ParameterStructure> output in arg.Output)
                        {
                            if (output.Value.Size <= 0)
                            {
                                DbCallback.AddOutputParameter(output.Value.Name, output.Value.sqlDbType);
                            }
                            else
                            {
                                DbCallback.AddOutputParameter(output.Value.Name, output.Value.sqlDbType, output.Value.Size);
                            }
                        }
                    }

                    // ------------------------------------------------
                    // Set return value
                    // ------------------------------------------------
                    DbCallback.SetReturnValue();

                    // ------------------------------------------------
                    // Execute!
                    // ------------------------------------------------
                    DbCallback.ExecuteNonQuery(conn, tx);

                    // ------------------------------------------------
                    // Get return output value
                    // ------------------------------------------------
                    if (arg.Output != null)
                    {
                        foreach (KeyValuePair <string, ParameterStructure> output in arg.Output)
                        {
                            output.Value.dbValue = DbCallback.OutputParameterToObject(output.Value.Name);
                        }
                    }

                    // ------------------------------------------------
                    // Stroe procedure name
                    // ------------------------------------------------
                    arg.ReturnValue = DbCallback.GetReturnValue();

                    // ------------------------------------------------
                    // Stroe procedure validation failed!
                    // ------------------------------------------------
                    if (arg.ReturnValue == -2)
                    {
                        if (arg.Output.ContainsKey("@MessageResult"))
                        {
                            throw new Exception(arg.Output["@MessageResult"].dbValue.ToString());
                        }
                        else if (arg.Output.ContainsKey("MessageResult"))
                        {
                            throw new Exception(arg.Output["MessageResult"].dbValue.ToString());
                        }
                        else
                        {
                            throw new Exception("Return value equals -2. It means there is some error ing store procedure.");
                        }
                    }
                }

                tx.Commit();
                CatchFlag = false;
                _ex       = null;
            }
            catch (Exception ex)
            {
                tx.Rollback();
                DbCallback.CloseConnection();
                CatchFlag = true;
                _ex       = ex;
            }
            conn.Close();
            if (CatchFlag)
            {
                throw _ex;
            }
        }
Exemple #21
0
        public void ExecuteNonQuery(string sprocName, Dictionary <string, ParameterStructure> inputs, out int returnValue, ref Dictionary <string, ParameterStructure> output)
        {
            try
            {
                // ------------------------------------------------
                // Initialize return value
                // ------------------------------------------------
                returnValue = -99;
                //rowCount = 0;
                //message = "";

                // ------------------------------------------------
                // Stroe procedure name
                // ------------------------------------------------
                DbCallback.SetCommandStoredProcedure(sprocName);

                // ------------------------------------------------
                // Input parameters
                // ------------------------------------------------
                if (inputs != null)
                {
                    foreach (KeyValuePair <string, ParameterStructure> e in inputs)
                    {
                        DbCallback.AddInputParameter(e.Value.Name, e.Value.sqlDbType, e.Value.dbValue);
                    }
                }
                //DbCallback.AddInputParameter("@Pid", SqlDbType.Int, e.PlantationId);
                //DbCallback.AddInputParameter("@Id", SqlDbType.BigInt, e.Id);
                //DbCallback.AddInputParameter("@Species", SqlDbType.NVarChar, e.Species);
                //DbCallback.AddInputParameter("@Detail", SqlDbType.NVarChar, e.Detail);
                //DbCallback.AddInputParameter("@ActivityDate", SqlDbType.DateTime, e.ActivityDate);
                //DbCallback.AddInputParameter("@PlantCount", SqlDbType.Int, e.PlantCount);
                //DbCallback.AddInputParameter("@PlantHeight", SqlDbType.Decimal, e.PlantHeight);
                //DbCallback.AddInputParameter("@AmountRate", SqlDbType.Decimal, e.AmountRate);
                //DbCallback.AddInputParameter("@AdvanceAmount", SqlDbType.Decimal, e.AdvanceAmount);
                //DbCallback.AddInputParameter("@TotalAmount", SqlDbType.Decimal, e.TotalAmount);
                //DbCallback.AddInputParameter("@UserID", SqlDbType.Int, e.UserId);

                // ------------------------------------------------
                // Output parameters
                // ------------------------------------------------
                if (output != null)
                {
                    foreach (KeyValuePair <string, ParameterStructure> e in output)
                    {
                        if (e.Value.Size <= 0)
                        {
                            DbCallback.AddOutputParameter(e.Value.Name, e.Value.sqlDbType);
                        }
                        else
                        {
                            DbCallback.AddOutputParameter(e.Value.Name, e.Value.sqlDbType, e.Value.Size);
                        }
                    }
                }
                //DbCallback.AddOutputParameter("@IntResult", SqlDbType.Int);
                //DbCallback.AddOutputParameter("@MessageResult", SqlDbType.NVarChar, 100);

                // ------------------------------------------------
                // Set return value
                // ------------------------------------------------
                DbCallback.SetReturnValue();

                // ------------------------------------------------
                // Execute
                // ------------------------------------------------
                DbCallback.ExecuteNonQuery();

                // ------------------------------------------------
                // Get return output value
                // ------------------------------------------------
                if (output != null)
                {
                    foreach (KeyValuePair <string, ParameterStructure> e in output)
                    {
                        e.Value.dbValue = DbCallback.OutputParameterToObject(e.Value.Name);
                    }
                }
                //rowCount = DbCallback.OutputParameterToInt("@IntResult");
                //message = DbCallback.OutputParameterToString("@MessageResult");

                // ------------------------------------------------
                // Stroe procedure name
                // ------------------------------------------------
                returnValue = DbCallback.GetReturnValue();
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }
Exemple #22
0
        public DataSet ExecuteToDataSet(string sprocName, Dictionary <string, ParameterStructure> inputs, out int returnValue, ref Dictionary <string, ParameterStructure> output)
        {
            try
            {
                returnValue = -99;
                DataSet ds = new DataSet();

                // -------------------------------------------
                // Store procedure
                // -------------------------------------------
                DbCallback.SetCommandStoredProcedure(sprocName); // all parameters cleared

                // -------------------------------------------
                // input parameters
                // -------------------------------------------
                if (inputs != null)
                {
                    foreach (KeyValuePair <string, ParameterStructure> param in inputs)
                    {
                        DbCallback.AddInputParameter(param.Value.Name, param.Value.sqlDbType, param.Value.dbValue);
                    }
                }

                // -------------------------------------------
                // output parameters
                // -------------------------------------------
                if (output != null)
                {
                    foreach (KeyValuePair <string, ParameterStructure> param in output)
                    {
                        if (param.Value.Size <= 0)
                        {
                            DbCallback.AddOutputParameter(param.Value.Name, param.Value.sqlDbType);
                        }
                        else
                        {
                            DbCallback.AddOutputParameter(param.Value.Name, param.Value.sqlDbType, param.Value.Size);
                        }
                    }
                }

                // -------------------------------------------
                // Set return
                // -------------------------------------------
                DbCallback.SetReturnValue();

                // -------------------------------------------
                // Execute
                // -------------------------------------------
                ds = DbCallback.ExecuteToDataSet();

                // -------------------------------------------
                // Get output parameters
                // -------------------------------------------
                if (output != null)
                {
                    foreach (KeyValuePair <string, ParameterStructure> param in output)
                    {
                        param.Value.dbValue = DbCallback.OutputParameterToObject(param.Value.Name);
                    }
                }

                // -------------------------------------------
                // Return value
                // -------------------------------------------
                returnValue = DbCallback.GetReturnValue();

                // -------------------------------------------
                // Return DataSet
                // -------------------------------------------
                if (ds != null)
                {
                    return(ds);
                }

                // -------------------------------------------
                // safety
                // -------------------------------------------
                return(null);
            }
            catch (Exception ex)
            {
                DbCallback.CloseConnection();
                throw ex;
            }
        }