Beispiel #1
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (tbxMaLoaiDonVi.Text == "")
            {
                MessageBox.Show("Vui lòng chọn loại đơn vị để sửa!");
                return;
            }

            if (!isSua)//Sua
            {
                tbxTenLoaiDonVi.ReadOnly = false;
                btnSua.Text     = "Hoàn tất";
                btnThem.Enabled = false;
                btnXoa.Enabled  = false;
            }
            else
            {
                if (tbxTenLoaiDonVi.Text.Length > 10)
                {
                    MessageBox.Show("Tên đơn vị không được quá 10 ký tự!");
                    return;
                }
                if (tbxTenLoaiDonVi.Text.Length == 0)
                {
                    MessageBox.Show("Tên đơn vị không được để trống!");
                    return;
                }
                try
                {
                    DTO_LoaiDonVi loaiDonVi = new DTO_LoaiDonVi(tbxMaLoaiDonVi.Text, tbxTenLoaiDonVi.Text);
                    if (!bus_loaiDonVi.Update(loaiDonVi))
                    {
                        MessageBox.Show("Sửa thất bại! Vui lòng kiểm tra lại!");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Sửa thành công!");
                        ReloadDSLoaiDonVi();
                    }
                }
                catch
                {
                    MessageBox.Show("Sửa thất bại! Vui lòng kiểm tra lại!");
                    return;
                }
                tbxTenLoaiDonVi.ReadOnly = true;
                btnSua.Text     = "Sửa";
                btnThem.Enabled = true;
                btnXoa.Enabled  = true;
            }

            isSua = !isSua;
        }
Beispiel #2
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (!isThem)//them
            {
                tbxMaLoaiDonVi.Text      = bus_loaiDonVi.GetMaLoaiDonViNext();
                tbxTenLoaiDonVi.ReadOnly = false;
                btnThem.Text             = "Hoàn tất";
                btnSua.Enabled           = false;
                btnXoa.Enabled           = false;
            }
            else//Luu
            {
                if (tbxTenLoaiDonVi.Text.Length == 0)
                {
                    MessageBox.Show("Tên đơn vị không được để trống!");
                    return;
                }
                if (tbxTenLoaiDonVi.Text.Length > 10)
                {
                    MessageBox.Show("Tên đơn vị không được quá 10 ký tự!");
                    return;
                }
                try
                {
                    DTO_LoaiDonVi loaiDonVi = new DTO_LoaiDonVi(tbxMaLoaiDonVi.Text, tbxTenLoaiDonVi.Text);
                    if (!bus_loaiDonVi.Add(loaiDonVi))
                    {
                        MessageBox.Show("Thêm thất bại! Vui lòng kiểm tra lại!");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Thêm thành công!");
                        ReloadDSLoaiDonVi();
                    }
                }
                catch
                {
                    MessageBox.Show("Thêm thất bại! Vui lòng kiểm tra lại!");
                    return;
                }

                btnThem.Text             = "Thêm";
                tbxTenLoaiDonVi.ReadOnly = true;
                btnSua.Enabled           = true;
                btnXoa.Enabled           = true;
            }
            isThem = !isThem;
        }
Beispiel #3
0
        public bool Add(DTO_LoaiDonVi pLoaiDonVi)
        {
            try
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from LOAIDONVI", _cn);
                DataRow        r  = dt.NewRow();
                r["MaLoaiDonVi"]  = pLoaiDonVi.MaLoaiDonVi;
                r["TenLoaiDonVi"] = pLoaiDonVi.TenLoaiDonVi;
                dt.Rows.Add(r);

                SqlCommandBuilder cm = new SqlCommandBuilder(da);
                da.Update(dt);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #4
0
 public bool Update(DTO_LoaiDonVi pLoaiDonVi)
 {
     try
     {
         SqlDataAdapter da = new SqlDataAdapter("select * from LOAIDONVI", _cn);
         DataRow        r  = dt.Rows.Find(pLoaiDonVi.MaLoaiDonVi);
         if (r != null)
         {
             r["MaLoaiDonVi"]  = pLoaiDonVi.MaLoaiDonVi;
             r["TenLoaiDonVi"] = pLoaiDonVi.TenLoaiDonVi;
         }
         SqlCommandBuilder cm = new SqlCommandBuilder(da);
         da.Update(dt);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public bool Update(DTO_LoaiDonVi pLoaiDonVi)
 {
     return(dal_loaiDonVi.Update(pLoaiDonVi));
 }
 public bool Add(DTO_LoaiDonVi pLoaiDonVi)
 {
     return(dal_loaiDonVi.Add(pLoaiDonVi));
 }