예제 #1
0
파일: HangHoa.cs 프로젝트: phu1123/QLCF
        private void btnThem_Click(object sender, EventArgs e)
        {
            foreach (var c in from MaterialSingleLineTextField c in tabThem.Controls.OfType<MaterialSingleLineTextField>() where c != txtGhiChu select c)
                errorProvider1.SetError(c, string.IsNullOrWhiteSpace(c.Text) ? "Bạn không được để trống thông tin này" : string.Empty);

            if (tabThem.Controls.OfType<MaterialSingleLineTextField>().Any(c => errorProvider1.GetError(c) != string.Empty)) return;

            try
            {
                using (HangHoaBUS bus = new HangHoaBUS())
                {
                    HangHoaDTO info = new HangHoaDTO
                    {
                        TenHangHoa = txtTenHangHoa.Text,
                        GiaBan = Convert.ToInt32(txtGiaBan.Text),
                        DonViTinh = txtDonViTinh.Text,
                        SoLuongTon = Convert.ToInt32(txtSoLuongTon.Text),
                        GhiChu = txtGhiChu.Text
                    };

                    if (dataGridView1.SelectedRows.Count == 0)
                        bus.InsertHangHoa(info);
                    else
                    {
                        string tenhanghoa = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                        bus.EditHangHoa(info, tenhanghoa);
                    }
                }
            }
            catch (SqlException ex)
            {
                if (ex.Number == DbConnection.MssqlEng002627)
                    errorProvider1.SetError(txtTenHangHoa, "Hàng hóa đã tồn tại");
                else throw;
            }

            RefreshHangHoa();
        }
예제 #2
0
파일: HangHoaDAO.cs 프로젝트: phu1123/QLCF
 public void InsertHangHoa(HangHoaDTO info)
 {
     string sql = $"INSERT INTO HangHoa VALUES(N'{info.TenHangHoa}', N'{info.GiaBan}', N'{info.DonViTinh}', N'{info.SoLuongTon}', N'{info.GhiChu}')";
     _dbconnection.ExcuteNonQuery(sql);
 }
예제 #3
0
파일: HangHoaBUS.cs 프로젝트: phu1123/QLCF
 public void InsertHangHoa(HangHoaDTO info)
 {
     _hanghoaDAO.InsertHangHoa(info);
 }
예제 #4
0
파일: HangHoaDAO.cs 프로젝트: phu1123/QLCF
 public void EditHangHoa(HangHoaDTO info, string tenhanghoa)
 {
     string sql = $"UPDATE HangHoa SET TenHangHoa=N'{info.TenHangHoa}', GiaBan=N'{info.GiaBan}', DonViTinh=N'{info.DonViTinh}', SoLuongTon=N'{info.SoLuongTon}', GhiChu=N'{info.GhiChu}' WHERE TenHangHoa=N'{tenhanghoa}'";
     _dbconnection.ExcuteNonQuery(sql);
 }
예제 #5
0
파일: HangHoaBUS.cs 프로젝트: phu1123/QLCF
 public void EditHangHoa(HangHoaDTO info, string tenhanghoa)
 {
     _hanghoaDAO.EditHangHoa(info, tenhanghoa);
 }