Example #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            DateTime         today   = DateTime.Now;
            string           maBCT   = BaoCaoTonBLL.GetMaBCT(today.Month, today.Year);
            string           maCTBCT = ChiTietBaoCaoTonBLL.getMaCTBCT(maBCT, cboPhuTung.Text);
            ChiTietBaoCaoTon chitiet = new ChiTietBaoCaoTon();

            chitiet.MaBCT    = maBCT;
            chitiet.MaCTBCT  = maCTBCT;
            chitiet.TenPT    = cboPhuTung.Text;
            chitiet.TonCuoi  = int.Parse(txtSL.Text);
            chitiet.PhatSinh = 0;
            chitiet.TonDau   = 0;
            ChiTietBaoCaoTonBLL.capNhatTonCuoi(chitiet);

            decimal thanhTien = decimal.Parse(txtThanhTien.Text);

            txtTongTien.Text = string.Format("{0:0,0}", decimal.Parse(tongTien.ToString()));

            string maCTPSC            = ChiTietPhieuSuaChuaBLL.AutoMACTSC();
            ChiTietPhieuSuaChua ctpsc = new ChiTietPhieuSuaChua(maCTPSC, txtMaPhieu.Text, cboPhuTung.SelectedValue.ToString(), int.Parse(txtSL.Text), cboNoiDung.Text, decimal.Parse(txtThanhTien.Text));

            int soLuongPTTon = int.Parse(PhuTungBLL.LaySoLuongPhuTung(cboPhuTung.Text));

            try
            {
                if (soLuongPTTon < int.Parse(txtSL.Text))
                {
                    MessageBox.Show("Số lượng phụ tùng trong kho không đủ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    ChiTietPhieuSuaChuaBLL.ThemCTPSC(ctpsc);
                    GetDataGridView();
                    tongTien        += thanhTien;
                    txtTongTien.Text = string.Format("{0:0,0}", decimal.Parse(tongTien.ToString()));
                    MessageBox.Show("Thêm chi tiết thành công!", "Thông báo", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            txtDonGia.Clear();
            txtSL.Clear();
            txtThanhTien.Clear();
            txtTienCong.Clear();
            cboNoiDung.Text = "";
            cboPhuTung.Text = "";
        }
Example #2
0
        private void btnThemSL_Click(object sender, EventArgs e)
        {
            int           soluong = int.Parse(txtSoLuong.Text);
            frmMuaPhuTung form    = new frmMuaPhuTung(txtSoLuong);

            form.ShowDialog();
            if (btnThayDoi.Enabled)
            {
                PhuTung phuTung = new PhuTung();
                phuTung.MaPhuTung  = txtMaVTPT.Text;
                phuTung.TenPhuTung = txtTenPT.Text;
                phuTung.SoLuong    = int.Parse(txtSoLuong.Text);

                //cap nhat phat sinh
                DateTime today = DateTime.Now;
                string   maBCT = BaoCaoTonBLL.GetMaBCT(today.Month, today.Year);

                if (maBCT == "")
                {
                    BaoCaoTon baocao = new BaoCaoTon();

                    baocao.MaBCT = BaoCaoTonBLL.AutoMABCT();
                    maBCT        = baocao.MaBCT;
                    baocao.Thang = today.Month;
                    baocao.Nam   = today.Year;
                    BaoCaoTonBLL.ThemBC(baocao);
                }

                string           maCTBCT = ChiTietBaoCaoTonBLL.getMaCTBCT(maBCT, phuTung.TenPhuTung);
                ChiTietBaoCaoTon chitiet = new ChiTietBaoCaoTon();

                chitiet.MaBCT    = maBCT;
                chitiet.MaCTBCT  = maCTBCT;
                chitiet.TenPT    = phuTung.TenPhuTung;
                chitiet.TonCuoi  = 0;
                chitiet.PhatSinh = int.Parse(txtSoLuong.Text) - soluong;
                chitiet.TonDau   = 0;
                ChiTietBaoCaoTonBLL.capNhatPhatSinh(chitiet);

                PhuTungBLL.ThayDoiSoLuongPhuTung(phuTung);
                GetDataGridView();
            }
        }