Example #1
0
        public string Update(DTOHoatChat data)
        {
            try
            {
                string        connect = Provider.Connecting();
                SqlConnection con     = new SqlConnection(connect);
                con.Open();
                SqlTransaction sqlTransaction = con.BeginTransaction();

                string     query = @"update dbo_HoatChat set HoatChat_Name=N'" + data.Name + "',MacDinh=" + data.MacDinh + " where HoatChat_ID='" + data.ID + "'";
                SqlCommand cmd   = new SqlCommand(query, con);
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = sqlTransaction;
                int result = cmd.ExecuteNonQuery();
                if (result != 1)
                {
                    sqlTransaction.Rollback();
                    sqlTransaction.Dispose();
                    con.Close();
                    return(@"Lỗi số 1 : DAOHoatChat ->Update : Cập nhật dữ liệu đơn vị tính lỗi");
                }

                sqlTransaction.Commit();
                sqlTransaction.Dispose();
                con.Close();
                return("SUCCESS");
            }
            catch (Exception e)
            {
                return(@"Lỗi ngoại lệ : DAOHoatChat ->Update : " + e.Message);
            }
        }
Example #2
0
 public string Delete(DTOHoatChat data)
 {
     try
     {
         DAOHoatChat daoHoatChat = new DAOHoatChat();
         return(daoHoatChat.Delete(data));
     }
     catch (Exception e)
     {
         return("Lỗi ngoại lệ: BUSHoatChat -> Delete: " + e.Message);
     }
 }
Example #3
0
        public string Insert(ref DTOHoatChat data)
        {
            try
            {
                DAOHoatChat daoHoatChat = new DAOHoatChat();

                return(daoHoatChat.Insert(ref data));
            }
            catch (Exception e)
            {
                return(@"Lỗi ngoại lệ : BUSHoatChat -> Insert : " + e.Message);
            }
        }
Example #4
0
        public string Insert(ref DTOHoatChat data)
        {
            try
            {
                string        connect = Provider.Connecting();
                SqlConnection con     = new SqlConnection(connect);
                con.Open();
                SqlTransaction sqlTransaction = con.BeginTransaction();
                string         query          = @"insert into dbo_HoatChat(HoatChat_Name,MacDinh) values(N'" + data.Name + "','" + data.MacDinh + "')";
                SqlCommand     cmd            = new SqlCommand(query, con);
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = sqlTransaction;
                int result = cmd.ExecuteNonQuery();
                if (result == 1)
                {
                    query = "SELECT IDENT_CURRENT('dbo_HoatChat')";
                    SqlCommand cmdID = new SqlCommand(query, con);
                    cmdID.CommandType = CommandType.Text;
                    cmdID.Transaction = sqlTransaction;

                    object id = cmdID.ExecuteScalar();
                    data.ID = id.ToString();
                    if (result > 0)
                    {
                        sqlTransaction.Commit();
                    }
                    else
                    {
                        sqlTransaction.Rollback();
                        sqlTransaction.Dispose();
                        con.Close();
                        return("Lỗi số 2 : DAOHoatChat -> Insert : Lấy mã đơn vị tính lỗi");
                    }
                }
                else
                {
                    sqlTransaction.Rollback();
                    sqlTransaction.Dispose();
                    con.Close();
                    return(@"Lỗi số 1 : DAOHoatChat ->Insert : Thêm dữ liệu đơn vị tính lỗi ");
                }
                sqlTransaction.Dispose();
                con.Close();
                return("SUCCESS");
            }
            catch (Exception e)
            {
                return("Lỗi ngoại lệ: DAOHoatChat -> Insert: " + e.Message);
            }
        }