private void btnSave_Click(object sender, EventArgs e)
        {
            if (!checkData())
            {
                return;
            }
            else
            {
                String unitName = Utils.standardNamePerson(txtUnitName.Text);
                unitObject = new DTOUnit("DOV0000000", unitName);

                if (unitBUS.InsertUnit(unitObject))
                {
                    XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    btnAdd.Enabled       = true;
                    btnCancelAdd.Enabled = false;
                    btnCancelAdd.Visible = false;
                    btnSave.Enabled      = false;
                }
                else
                {
                    XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                }
            }
        }
Example #2
0
        public string Update(DTOUnit data)
        {
            try
            {
                string        connect = Provider.Connecting();
                SqlConnection con     = new SqlConnection(connect);
                con.Open();
                SqlTransaction sqlTransaction = con.BeginTransaction();

                string     query = @"update Unit set Unit_Name=N'" + data.Name + "',IsDefault=" + data.IsDefault + " where Unit_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 : DAOUnit ->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ệ : DAOUnit ->Update : " + e.Message);
            }
        }
Example #3
0
 /// <summary>
 /// Phương thức cập nhật một Unit xuống csdl theo id
 /// </summary>
 /// <returns>true: thêm mới thành công, false: thêm mới thất bại</returns>
 public bool UpdateUnit(DTOUnit Unit)
 {
     try
     {
         return(unitDAO.UpdateUnit(Unit));
     }
     catch (SqlException)
     {
         throw;
     }
 }
Example #4
0
 /// <summary>
 /// Phương thức thêm mới một Unit vào csdl
 /// </summary>
 /// <returns>true: thêm mới thành công, false: thêm mới thất bại</returns>
 public bool InsertUnit(DTOUnit Unit)
 {
     try
     {
         return(unitDAO.InsertUnit(Unit));
     }
     catch (SqlException)
     {
         throw;
     }
 }
Example #5
0
 public string Insert(ref DTOUnit data)
 {
     try
     {
         DAOUnit daoUnit = new DAOUnit();
         return(daoUnit.Insert(ref data));
     }
     catch (Exception e)
     {
         return(@"Lỗi ngoại lệ : BUSUnit -> Insert : " + e.Message);
     }
 }
Example #6
0
 public string Delete(DTOUnit data)
 {
     try
     {
         DAOUnit daoUnit = new DAOUnit();
         return(daoUnit.Delete(data));
     }
     catch (Exception e)
     {
         return("Lỗi ngoại lệ: BUSUnit -> Delete: " + e.Message);
     }
 }
Example #7
0
 /// <summary>
 /// Phương thức cập nhật một Unit xuống csdl theo id
 /// </summary>
 /// <returns>true: thêm mới thành công, false: thêm mới thất bại</returns>
 public bool UpdateUnit(DTOUnit Unit)
 {
     try
     {
         DataExecute.Instance.createSqlCmd("sp_EditUnitUpdate" /*Truyen vao storeprocedure*/, new object[2] {
             Unit.UnitID, Unit.UnitName
         });
         return(DataExecute.Instance.updateData(DataConnection.Instance.m_cmd) > 0);
     }
     catch (SqlException)
     {
         throw;
     }
 }
Example #8
0
        public string Insert(ref DTOUnit data)
        {
            try
            {
                string        connect = Provider.Connecting();
                SqlConnection con     = new SqlConnection(connect);
                con.Open();
                SqlTransaction sqlTransaction = con.BeginTransaction();
                string         query          = @"insert into Unit(Unit_Name,IsDefault) values(N'" + data.Name + "','" + data.IsDefault + "')";
                SqlCommand     cmd            = new SqlCommand(query, con);
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = sqlTransaction;
                int result = cmd.ExecuteNonQuery();
                if (result == 1)
                {
                    query = "SELECT IDENT_CURRENT('UNIT')";
                    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 : DAOUnit -> Insert : Lấy mã đơn vị tính lỗi");
                    }
                }
                else
                {
                    sqlTransaction.Rollback();
                    sqlTransaction.Dispose();
                    con.Close();
                    return(@"Lỗi số 1 : DAOUnit ->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ệ: DAOUnit -> Insert: " + e.Message);
            }
        }
Example #9
0
        private void SaveDataToDatabase()
        {
            if (!checkData())
            {
                return;
            }
            try
            {
                if (m_IsAdd)
                {
                    String unitName = Utils.standardNamePerson(txtUnitName.Text);
                    unitObject = new DTOUnit("DOV0000000", unitName);

                    if (unitBUS.InsertUnit(unitObject))
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
                else
                {
                    String unitName = Utils.standardNamePerson(txtUnitName.Text);
                    unitObject = new DTOUnit(txtUnitId.Text, unitName);

                    if (unitBUS.UpdateUnit(unitObject))
                    {
                        XtraCustomMessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Cập nhật dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
            }
            catch (System.Exception ex)
            {
                XtraCustomMessageBox.Show(ex.ToString(), "Lỗi", true, 3);
            }
            finally
            {
                updateEnableButtonAndResetValueOfControl(ref btnSave);
            }
        }
Example #10
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (unitMulitiSelect.Selection.Count == 0)
     {
         XtraCustomMessageBox.Show("Chưa có dòng dữ liệu nào được chọn!", "Thông báo", true, 1);
         return;
     }
     try
     {
         System.Collections.ArrayList _listunitObjectInDelibility = new System.Collections.ArrayList();
         foreach (object _rowObjectItem in unitMulitiSelect.Selection)
         {
             grdvListUnit.FocusedRowHandle -= 1;
             DataRowView _rowObjectDetail = _rowObjectItem as DataRowView;
             unitObject = new DTOUnit(_rowObjectDetail.Row["UnitID"].ToString(), _rowObjectDetail.Row["UnitName"].ToString());
             if (!unitBUS.DeleteUnit(unitObject.UnitID))
             {
                 _listunitObjectInDelibility.Add(_rowObjectDetail.Row["UnitID"]);
             }
         }
         String _erroContent = "Không thể xóa thông tin các thế loại sách có mã số: \n";
         if (_listunitObjectInDelibility.Count != 0)
         {
             foreach (var item in _listunitObjectInDelibility)
             {
                 _erroContent += item.ToString() + "\n";
             }
             XtraCustomMessageBox.Show(_erroContent, "Lỗi", true, 4);
         }
         else
         {
             XtraCustomMessageBox.Show("Xóa dữ liệu thành công", "Thông báo", true, 1);
         }
     }
     catch (System.Exception)
     {
         XtraCustomMessageBox.Show("Xóa dữ liệu thất bại", "Lỗi", true, 4);
     }
     finally
     {
         updateEnableButtonAndResetValueOfControl(ref btnDelete);
     }
 }