private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            string mapn         = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            string malpx        = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            string manv         = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            string mattp        = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            string ngaylapphieu = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            string ngaynhap     = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
            string nd           = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();

            Form form = new ChiTietPhieuNhap(mapn, malpx, manv, mattp, ngaylapphieu, ngaynhap, nd);

            form.Show();
        }
Exemple #2
0
        private ChiTietPhieuNhap GetDataChiTietPN()
        {
            if (txtSoLuong.Text == "")
            {
                txtSoLuong.Text = "0";
            }
            ChiTietPhieuNhap chiTiet = new ChiTietPhieuNhap()
            {
                MaPN      = txtMaPN.Text,
                MaHH      = MaHH(),
                SoLuong   = int.Parse(txtSoLuong.Text),
                ThanhTien = float.Parse(txtThanhTien.Text),
                GhiChu    = rtxtGhiChu.Text
            };

            return(chiTiet);
        }
Exemple #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ChiTietPhieuNhap chiTiet;

            if (importNew == true)
            {
                PhieuNhap phieuNhap = new PhieuNhap()
                {
                    MaPN      = txtMaPN.Text.ToUpper(),
                    MaNV      = Config.CURRENT_NHANVIEN,
                    MaNCC     = cbbTenNCC.SelectedValue.ToString(),
                    NgayNhap  = dtpNgayNhap.Value,
                    ChietKhau = 0,
                    ThanhTien = int.Parse(txtTongTien.Text),
                    TongTien  = int.Parse(txtTongTien.Text),
                    GhiChu    = rtxtGhiChu.Text
                };
                int res = Bus.AddPhieuNhap(phieuNhap);
                int result;
                chiTiet = new ChiTietPhieuNhap();
                foreach (DataRow dr in dataTableChiTiet.Rows)
                {
                    chiTiet = new ChiTietPhieuNhap()
                    {
                        MaHH      = dr["MaHH"].ToString(),
                        MaPN      = dr["MaPN"].ToString(),
                        SoLuong   = int.Parse(dr["SoLuong"].ToString()),
                        GhiChu    = dr["GhiChu"].ToString(),
                        ThanhTien = int.Parse(dr["ThanhTien"].ToString()),
                        DonGia    = int.Parse(dr["DonGia"].ToString())
                    };
                    result = Bus.AddChiTietPhieuNhap(chiTiet);
                }
                //   int res = Bus.AddPhieuNhap(phieuNhap);
                //  int result = Bus.AddChiTietPhieuNhap(chiTiet);

                if (res > 0)
                {
                    MessageBox.Show("Thêm hóa đơn thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon
                                    .Information);
                }
                else
                {
                    MessageBox.Show("Thêm hóa đơn thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon
                                    .Information);
                }
            }

            else
            {
                PhieuNhap phieuNhap = new PhieuNhap()
                {
                    MaPN      = txtMaPN.Text.ToUpper(),
                    MaNV      = Config.CURRENT_NHANVIEN,
                    MaNCC     = cbbTenNCC.SelectedValue.ToString(),
                    NgayNhap  = dtpNgayNhap.Value,
                    ChietKhau = 0,
                    ThanhTien = int.Parse(txtTongTien.Text),
                    TongTien  = int.Parse(txtTongTien.Text),
                    GhiChu    = rtxtGhiChu.Text
                };
                int a = Bus.DeleteCTPN(MaPN);

                chiTiet = new ChiTietPhieuNhap();
                foreach (DataRow dr in dataTableChiTiet.Rows)
                {
                    chiTiet           = new ChiTietPhieuNhap();
                    chiTiet.MaHH      = dr["MaHH"].ToString();
                    chiTiet.MaPN      = dr["MaPN"].ToString();
                    chiTiet.SoLuong   = int.Parse(dr["SoLuong"].ToString());
                    chiTiet.GhiChu    = dr["GhiChu"].ToString();
                    chiTiet.ThanhTien = int.Parse(dr["ThanhTien"].ToString());
                    chiTiet.DonGia    = int.Parse(dr["DonGia"].ToString());

                    int result = Bus.UpdateChiTietPhieuNhap(chiTiet);
                }
                int res = Bus.UpdatePhieuNhap(phieuNhap);
                //          int a = Bus.DeleteCTPN(MaPN);
                //   int result = Bus.UpdateChiTietPhieuNhap(chiTiet);
                if (res > 0)
                {
                    MessageBox.Show("Update thanh cong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon
                                    .Information);
                }
                else
                {
                    MessageBox.Show("Update that bai", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon
                                    .Information);
                }
            }
            //     MessageBox.Show("Thêm Hóa Đơn thành công!", "Thông báo", MessageBoxButtons.OK);
            this.Close();
        }
Exemple #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            tongTien = 0;
            if (txtDonGia.Text == "" || txtDonGia.Text == null)
            {
                MessageBox.Show("Nhap don gia");
            }
            txtThanhTien.Text = (int.Parse(txtDonGia.Text) * int.Parse(txtSoLuong.Text)).ToString();
            if (tongTien > 1700000000)
            {
                MessageBox.Show("Số tiền của bạn quá cao");
            }
            else
            {
                if (action == 1)
                {
                    foreach (DataRow dr in dataTableChiTiet.Rows)
                    {
                        if (dr["MaHH"].ToString() == cbbTenHH.SelectedValue.ToString())
                        {
                            int quantity = int.Parse(txtSoLuong.Text);
                            int b        = int.Parse((int.Parse(txtDonGia.Text) * (quantity - int.Parse(dr["SoLuong"].ToString()))).ToString());
                            //if ((quantity - int.Parse(dr["SoLuong"].ToString())) > 0)
                            //{
                            //    tongTien = tongTien + b;
                            //}
                            //else
                            //{
                            //    tongTien = tongTien - (int.Parse(txtDonGia.Text) * (int.Parse(dr["SoLuong"].ToString()) - quantity));
                            //}

                            dr["SoLuong"]   = quantity;
                            dr["ThanhTien"] = quantity * int.Parse(txtDonGia.Text);
                            dr["DonGia"]    = txtDonGia.Text;
                            btnAdd.Text     = "Thêm";
                            //  tongTien = 0;
                        }
                        tongTien += int.Parse(dr["ThanhTien"].ToString());
                    }
                }
                else
                {
                    int a = 0;
                    foreach (DataRow dr in dataTableChiTiet.Rows)
                    {
                        if (dr["MaHH"].ToString() == cbbTenHH.SelectedValue.ToString())
                        {
                            a = 1;
                            int quantity = int.Parse(txtSoLuong.Text);
                            dr["SoLuong"]   = int.Parse(dr["SoLuong"].ToString()) + quantity;
                            dr["ThanhTien"] = int.Parse(dr["SoLuong"].ToString()) * int.Parse(txtDonGia.Text);
                            dr["DonGia"]    = txtDonGia.Text;
                            //tongTien = 0;
                            tongTien += int.Parse(dr["ThanhTien"].ToString());
                        }
                    }
                    if (a != 1)
                    {
                        DataRow          newChiTiet = dataTableChiTiet.NewRow();
                        ChiTietPhieuNhap chiTiet    = GetDataChiTietPN();
                        newChiTiet["MaPN"]      = chiTiet.MaPN;
                        newChiTiet["MaHH"]      = chiTiet.MaHH;
                        newChiTiet["TenHang"]   = cbbTenHH.Text;
                        newChiTiet["SoLuong"]   = chiTiet.SoLuong;
                        newChiTiet["DonGia"]    = txtDonGia.Text;
                        newChiTiet["ThanhTien"] = chiTiet.SoLuong * int.Parse(txtDonGia.Text);
                        newChiTiet["GhiChu"]    = rtxtGhiChu.Text;
                        dataTableChiTiet.Rows.Add(newChiTiet);
                        dgvChiTietPhieuNhap.DataSource = dataTableChiTiet;
                        foreach (DataRow dr in dataTableChiTiet.Rows)
                        {
                            // tongTien = 0;
                            tongTien += int.Parse(dr["ThanhTien"].ToString());
                        }
                    }
                    dgvChiTietPhieuNhap.DataSource = dataTableChiTiet;
                    //    tongTien = tongTien + int.Parse(txtThanhTien.Text);
                }
                txtTongTien.Text        = tongTien.ToString();
                btnAddNewImport.Enabled = true;
                btnSave.Enabled         = true;
                btnCancel.Enabled       = false;
                btnEdit.Enabled         = false;
                btnDelete.Enabled       = false;
                btnAdd.Enabled          = false;
                txtSoLuong.Enabled      = false;
                cbbTenHH.Enabled        = false;
                txtDonGia.Text          = "0";
                txtDonGia.Enabled       = false;
                status = 0;
                action = 0;
            }
        }