Пример #1
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells[0];

            if (cb.Value != null && (lastId == "null" || lastId != cb.Value?.ToString()) || lastLine == -1 || lastLine != e.RowIndex)
            {
                lastLine = e.RowIndex;
                lastId   = cb.Value.ToString();
                DM_HANG dM_HANG = dM_HANGs.FirstOrDefault(x => x.MA_HANG == cb.Value.ToString());
                dataGridView1.Rows[e.RowIndex].Cells[1].Value = dM_HANG.TEN_HANG;
                dataGridView1.Rows[e.RowIndex].Cells[2].Value = dM_HANG.DVT;
                dataGridView1.Rows[e.RowIndex].Cells[4].Value = dM_HANG.DON_GIA_BAN;
                dataGridView1.Rows[e.RowIndex].Cells[5].Value = 0;
            }
            DataGridViewTextBoxCell soluong = (DataGridViewTextBoxCell)dataGridView1.Rows[e.RowIndex].Cells[3];

            if (!String.IsNullOrWhiteSpace(soluong.Value?.ToString()) && (lastSoLuong == "null" || lastSoLuong != soluong.Value?.ToString()) || lastLine == -1 || lastLine != e.RowIndex)
            {
                lastLine = e.RowIndex;
                float.TryParse(soluong.Value.ToString(), out float temp);
                float.TryParse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(), out float temp2);
                dataGridView1.Rows[e.RowIndex].Cells[5].Value = temp * temp2;
            }
            if (e.ColumnIndex == 5)
            {
                txtTong.Text = CellSum().ToString();
            }
        }
Пример #2
0
        private void s_Click(object sender, EventArgs e)
        {
            var selected = gvDSHang.GetFocusedRow() as dynamic;

            if (selected != null)
            {
                var confirmResult = XtraMessageBox.Show("Bạn có thực sự muốn xóa ??",
                                                        "Xác nhận xóa!",
                                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (confirmResult == DialogResult.Yes)
                {
                    try
                    {
                        string  id   = selected.MA_HANG.ToString();
                        DM_HANG hang = dbContext.DM_HANG.FirstOrDefault(x => x.MA_HANG == id);
                        dbContext.DM_HANG.Remove(hang);
                        dbContext.SaveChanges();
                        loadData();
                        XtraMessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        XtraMessageBox.Show("Không thể xóa hàng hóa đã được lập trong phiếu thu hoạc phiếu bán!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                XtraMessageBox.Show("Chọn MỘT hàng để xóa!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.isCreate)
     {
         // tao moi
         HangHoa = new DM_HANG();
         string maHang  = txtMa.Text.Trim();
         string tenHang = txtTen.Text.Trim();
         if (String.IsNullOrEmpty(maHang) || String.IsNullOrEmpty(tenHang))
         {
             XtraMessageBox.Show("Mã hàng và tên hàng chưa được điền!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             if (DataProvider.Ins.DB.DM_HANG.Any(x => x.MA_HANG == maHang))
             {
                 XtraMessageBox.Show("Mã hàng hóa đã tông tại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 HangHoa.MA_HANG  = maHang;
                 HangHoa.TEN_HANG = tenHang;
                 HangHoa.DVT      = txtDVT.Text;
                 decimal.TryParse(txtDonGia.Text, out decimal donGia);
                 HangHoa.DON_GIA = donGia;
                 decimal.TryParse(txtGiaBan.Text, out decimal giaBan);
                 HangHoa.DON_GIA_BAN = giaBan;
                 HangHoa.MA_ST       = d.Text;
                 HangHoa.GHI_CHU     = txtNote.Text;
                 DataProvider.Ins.DB.DM_HANG.Add(HangHoa);
                 DataProvider.Ins.DB.SaveChanges();
                 XtraMessageBox.Show("Lưu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Close();
             }
         }
     }
     else
     {
     }
 }
Пример #4
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            var selected = gvDSHang.GetFocusedRow() as dynamic;

            if (selected != null)
            {
                string  id   = selected.MA_HANG.ToString();
                DM_HANG hang = dbContext.DM_HANG.FirstOrDefault(x => x.MA_HANG == id);
                if (hang != null)
                {
                    AddhangHoa addhangHoa = new AddhangHoa(hang, false);
                    addhangHoa.Show();
                }
                else
                {
                    XtraMessageBox.Show("Mã hàng không tồn tại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                XtraMessageBox.Show("Chọn MỘT hàng để xem chi tiết!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #5
0
 public AddhangHoa(DM_HANG hangHoa = null, bool isCreate = true)
 {
     InitializeComponent();
     this.HangHoa  = hangHoa;
     this.isCreate = isCreate;
 }