Beispiel #1
0
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            string message;
            int    MaHD = MaxHD() + 1;

            blHD.Insert(MaHD, out message);
            bool result = true;

            for (int i = 0; i < listItem.Count; i++)
            {
                int        value = (int)(listItem[i].Tag);
                CHITIET_HD ct    = new CHITIET_HD();
                ct.MaHD = MaHD;
                ct.MaSP = value;
                ct.SL   = listItem[i].SoLuong;
                result  = blCT.Insert(ct, out message);
                if (result == false)
                {
                    MessageBox.Show(message);
                    return;
                }
            }
            MessageBox.Show("Thực hiện thành công");
            listItem.Clear();
            flpSanPham.Controls.Clear();
            for (int i = 0; i < dsVSP.Count; i++)
            {
                if (listPi[i] == null)
                {
                    break;
                }
                listPi[i].Count = 0;
            }
            pnThanhToan.Visible = false;
        }
Beispiel #2
0
 public bool Insert(CHITIET_HD ct, out string message)
 {
     message = "";
     try
     {
         //QLBH_FastFoodDataContext context = new QLBH_FastFoodDataContext();
         Global.global_datacontext.sp_ThemChiTietHD(ct.MaHD, ct.MaSP, ct.SL);
         return(true);
     }
     catch (Exception e)
     {
         message = e.Message;
     }
     return(false);
 }
Beispiel #3
0
 private void AddCTHD()
 {
     for (int j = 0; j < cthd3DataGridView.Rows.Count; j++)
     {
         CHITIET_HD cthd = new CHITIET_HD();
         cthd.MAHD       = txthoadon.Text;
         cthd.MASP       = cthd3DataGridView.Rows[j].Cells[5].Value.ToString();
         cthd.SOLUONG    = int.Parse(cthd3DataGridView.Rows[j].Cells[1].Value.ToString());
         cthd.DONGIA     = decimal.Parse(cthd3DataGridView.Rows[j].Cells[2].Value.ToString());
         cthd.THANHTIEN  = decimal.Parse(cthd3DataGridView.Rows[j].Cells[4].Value.ToString());
         cthd.GIAMGIA    = int.Parse(cthd3DataGridView.Rows[j].Cells[3].Value.ToString());
         cthd.TENSANPHAM = cthd3DataGridView.Rows[j].Cells[0].Value.ToString();
         BH.CHITIET_HDs.InsertOnSubmit(cthd);
     }
     BH.SubmitChanges();
 }
Beispiel #4
0
 public bool Insert(CHITIET_HD ct, out string message)
 {
     message = "Thanh toán thành công";
     try
     {
         QuanLyBanHangDataContext context = new QuanLyBanHangDataContext();
         context.CHITIET_HDs.InsertOnSubmit(ct);
         context.SubmitChanges();
         return(true);
     }
     catch (Exception e)
     {
         message = e.Message;
     }
     return(false);
 }
        private List <CHITIET_HD> convertGioHang(ListView lstGioHang)
        {
            List <CHITIET_HD> res = new List <CHITIET_HD>();

            foreach (ListViewItem item in lstGioHang.Items)
            {
                CHITIET_HD CTHD = new CHITIET_HD();
                CTHD.MAHD      = txtMaHoaDon.Text;
                CTHD.MASP      = item.SubItems[5].Text;
                CTHD.TENHH     = item.SubItems[1].Text.Trim();
                CTHD.GIABAN    = item.SubItems[2].Text.Trim();
                CTHD.SL_MUA    = int.Parse(item.SubItems[3].Text.Trim());
                CTHD.THANHTIEN = item.SubItems[4].Text.Trim();
                res.Add(CTHD);
            }
            return(res);
        }
Beispiel #6
0
 public bool Update(CHITIET_HD ct, out string message)
 {
     message = "";
     try
     {
         QuanLyBanHangDataContext context = new QuanLyBanHangDataContext();
         CHITIET_HD chitiet = context.CHITIET_HDs.FirstOrDefault(x => x.MaHD == ct.MaHD && x.MaSP == ct.MaSP);
         if (chitiet != null)
         {
             chitiet.SoLuong = ct.SoLuong;
             context.SubmitChanges();
             return(true);
         }
         message = "Khong co gia tri";
         return(false);
     }
     catch (Exception e)
     {
         message = e.Message;
     }
     return(false);
 }
Beispiel #7
0
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            string message;
            HOADON hd = new HOADON();

            hd.MaHD      = MaxHD() + 1;
            hd.TongTien  = ThanhTien;
            hd.TongGiaSP = TongGiaSP;
            hd.Ngay      = DateTime.Now.Day;
            hd.Thang     = DateTime.Now.Month;
            hd.Nam       = DateTime.Now.Year;
            hd.TT_HD     = true;
            blHD.Insert(hd, out message);

            for (int i = 0; i < listItem.Count; i++)
            {
                int        value = (int)(listItem[i].Tag);
                CHITIET_HD ct    = new CHITIET_HD();
                ct.MaHD    = hd.MaHD;
                ct.MaSP    = value;
                ct.SoLuong = listItem[i].SoLuong;
                blCT.Insert(ct, out message);
            }
            MessageBox.Show(message);
            listItem.Clear();
            flpSanPham.Controls.Clear();
            for (int i = 0; i < dsSP.Count; i++)
            {
                if (listPi[i] == null)
                {
                    break;
                }
                listPi[i].Count = 0;
            }
            pnThanhToan.Visible = false;
        }
Beispiel #8
0
        private void gr_bh_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            /*Thanh Toán*/
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 2)
            {
                //try
                //{
                if (txttienkhachdua.Text == "" || txttongtien.Text == "")
                {
                    MessageBox.Show("Tiền khách đưa không hợp lệ.", "Thông báo!!");
                }
                else if (double.Parse(txttienkhachdua.Text) <= double.Parse(txttongtien.Text))
                {
                    MessageBox.Show("Tiền khách đưa không hợp lệ!!");
                }
                else
                {
                    if (txtkhachang.Text == "")
                    {
                        MessageBox.Show("Tên khách hàng không được để trống!!!");
                    }
                    else
                    {
                        AddKH();
                        AddCTHD();
                        XtraMessageBox.Show("Lưu thành công", "Thông báo");
                        double tienlai = tientralai();
                        txttientralai.Text = string.Format("{0:n0}", Double.Parse(tienlai.ToString()));

                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            string ten = dataGridView1.Rows[i].Cells[4].Value.ToString();
                            int    sl  = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
                            updatesp(ten, sl);
                        }
                        //updatesp();
                        loaddulieu();
                        gridControl2.Enabled = true;
                    }
                }

                //}


                //catch (Exception ex)
                //{ MessageBox.Show(ex.Message); }
            }

            /*Thêm mới hoá đơn*/
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 1)
            {
                randomma();
                ngaylap();
                txtkhachang.Enabled     = true;
                txtsdt.Enabled          = true;
                txtghichu.Enabled       = true;
                txttienkhachdua.Enabled = true;
                btnthem.Enabled         = true;
                btnxoa.Enabled          = true;
                txtsdt.Text             = "";
                txtkhachang.Text        = "";
                txttongtien.Text        = "";
                txtghichu.Text          = "";
                txttienkhachdua.Text    = "";
                gridControl2.Enabled    = false;
                cthd3DataGridView.Columns.Clear();
                cmbtungay.Enabled         = false;
                cmbdenngay.Enabled        = false;
                simpleButton1.Enabled     = false;
                cthd3DataGridView.Enabled = true;
                dataGridView1.Enabled     = true;
                gr_bh.CustomHeaderButtons[2].Properties.Enabled = false;
                gr_bh.CustomHeaderButtons[3].Properties.Enabled = false;
                gr_bh.CustomHeaderButtons[1].Properties.Enabled = true;
                if (cthd3DataGridView.Columns.Contains("TENSP"))
                {
                    cthd3DataGridView.Columns.Remove("TENSP");
                    cthd3DataGridView.Columns.Remove("SOLUONG");
                    cthd3DataGridView.Columns.Remove("DONGIA");
                    cthd3DataGridView.Columns.Remove("GIAMGIA");
                    cthd3DataGridView.Columns.Remove("THANHTIEN");
                    //cthd3DataGridView.Columns.Remove("colmasp");
                }
                cthd3DataGridView.Refresh();
            }
            else
            /*Xoá hoá đơn và chi tiết hoá đơn*/
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 3)
            {
                MessageBox.Show("Xoá nè hihi");
                if (txthoadon.Text == "")
                {
                    MessageBox.Show("Vui lòng chọn hoá đơn cần xoá.");
                }
                else
                {
                    HOADON     hd   = new HOADON();
                    CHITIET_HD cthd = new CHITIET_HD();

                    hd   = BH.HOADONs.Where(s => s.MAHD == txthoadon.Text).Single();
                    cthd = BH.CHITIET_HDs.Where(s => s.MAHD == txthoadon.Text).Single();
                    BH.CHITIET_HDs.DeleteOnSubmit(cthd);
                    BH.HOADONs.DeleteOnSubmit(hd);
                    BH.SubmitChanges();
                    loaddulieu();
                    txtghichu.Text       = "";
                    txthoadon.Text       = "";
                    txtkhachang.Text     = "";
                    txtsdt.Text          = "";
                    txttienkhachdua.Text = "";
                    txttientralai.Text   = "";
                    txttongtien.Text     = "";
                    cmbngaylap.Text      = "";
                    MessageBox.Show("Xoá thành công.");
                    // gridhanghoa.Enabled = false;
                    //cmbloaisp.Text = "";
                    //cmbnhacungcap.Text = "";
                    //ptanh.Image = null;
                }
            }
            else
            {
                if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 5)
                {
                    rephoadon rpt = new rephoadon();
                    //rpt.FilterString = "[MAHD]='" + txthoadon.Text + "'";
                    rpt.Parameters["mahd"].Value        = txthoadon.Text;
                    rpt.Parameters["ngaylap"].Value     = cmbngaylap.Text;
                    rpt.Parameters["nhanvien"].Value    = txtnhanvienlap.Text;
                    rpt.Parameters["khachhang"].Value   = txtkhachang.Text;
                    rpt.Parameters["sodienthoai"].Value = txtsdt.Text;
                    rpt.Parameters["tongtien"].Value    = txttongtien.Text;
                    rpt.Parameters["tientralai"].Value  = txttientralai.Text;
                    rpt.Parameters["tiendua"].Value     = txttienkhachdua.Text;

                    rpt.DataSource = tk.chthd(txthoadon.Text);
                    //for (int j = 0; j < cthd3DataGridView.Rows.Count; j++)
                    //{

                    //    rpt.Parameters["tensanpham"].Value= int.Parse(cthd3DataGridView.Rows[j].Cells[1].Value.ToString());
                    //    rpt.Parameters["thanhtien"].Value = decimal.Parse(cthd3DataGridView.Rows[j].Cells[4].Value.ToString());
                    //    rpt.Parameters["giamgia"].Value = int.Parse(cthd3DataGridView.Rows[j].Cells[3].Value.ToString());
                    //    rpt.Parameters["tensanpham"].Value= cthd3DataGridView.Rows[j].Cells[0].Value.ToString();
                    //    rpt.Parameters["dongia"].Value = cthd3DataGridView.Rows[j].Cells[2].Value.ToString();
                    //    rpt.CreateDocument();
                    //}
                    //rpt.CreateDocument();
                    if (MessageBox.Show("Xác nhận thông tin Export", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        FolderBrowserDialog chuc = new FolderBrowserDialog();
                        if (chuc.ShowDialog() == DialogResult.OK)
                        {
                            string filePath = chuc.SelectedPath + "\\Export_BaoCao.docx" + txthoadon.Text;
                            rpt.ExportToDocx(filePath);
                        }
                    }

                    rpt.ShowPreviewDialog();
                }
            }
        }
Beispiel #9
0
        private void gr_bh_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            /*Thanh Toán*/
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 2)
            {
                try
                {
                    if (txttienkhachdua.Text == "" || txttongtien.Text == "")
                    {
                        MessageBox.Show("Tiền khách đưa không hợp lệ.", "Thông báo!!");
                    }
                    else if (double.Parse(txttienkhachdua.Text) <= double.Parse(txttongtien.Text))
                    {
                        MessageBox.Show("Tiền khách đưa không hợp lệ!!");
                    }
                    else
                    {
                        if (txtkhachang.Text == "")
                        {
                            MessageBox.Show("Tên khách hàng không được để trống!!!");
                        }
                        else
                        {
                            AddKH();
                            AddCTHD();
                            XtraMessageBox.Show("Lưu thành công", "Thông báo");
                            double tienlai = tientralai();
                            txttientralai.Text = string.Format("{0:n0}", Double.Parse(tienlai.ToString()));
                            loaddulieu();
                            updatesp();
                            gridControl2.Enabled = true;
                            //cthd3DataGridView.DataSource = null;
                            //frmBanHang_Load(sender, e);
                            //int gvHasRows = cthd3DataGridView.Rows.Count;
                            //if (gvHasRows > 0)
                            //{
                            //    cthd3DataGridView.Columns.Clear();
                            //    cthd3DataGridView.DataBind();
                            //}
                            //Form form = IsActive12(typeof(QuanLy_DienThoai.Views.frmBanHang));
                            //if (form == null)
                            //{
                            //    frmBanHang Child = new frmBanHang();
                            //    //Child.MdiParent = this;
                            //    Child.Show();
                            //}
                            //else
                            //    form.Activate();
                            //cthd3DataGridView.Columns.Clear();
                            //cthd3DataGridView.Refresh();
                            //enable();
                        }
                        //AddHD();

                        //XtraMessageBox.Show("Thành Công", "Thông báo");
                    }
                }
                catch (Exception ex)
                { MessageBox.Show(ex.Message); }
            }

            /*Thêm mới hoá đơn*/
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 1)
            {
                randomma();
                ngaylap();
                txtkhachang.Enabled     = true;
                txtsdt.Enabled          = true;
                txtghichu.Enabled       = true;
                txttienkhachdua.Enabled = true;
                btnthem.Enabled         = true;
                btnxoa.Enabled          = true;
                txtsdt.Text             = "";
                txtkhachang.Text        = "";
                txttongtien.Text        = "";
                txtghichu.Text          = "";
                txttienkhachdua.Text    = "";
                gridControl2.Enabled    = false;
                cthd3DataGridView.Columns.Clear();
                cmbtungay.Enabled           = false;
                cmbdenngay.Enabled          = false;
                simpleButton1.Enabled       = false;
                cthd3DataGridView.Enabled   = true;
                sANPHAMDataGridView.Enabled = true;
                gr_bh.CustomHeaderButtons[2].Properties.Enabled = false;
                gr_bh.CustomHeaderButtons[3].Properties.Enabled = false;
                gr_bh.CustomHeaderButtons[1].Properties.Enabled = true;
                if (cthd3DataGridView.Columns.Contains("TENSP"))
                {
                    cthd3DataGridView.Columns.Remove("TENSP");
                    cthd3DataGridView.Columns.Remove("SOLUONG");
                    cthd3DataGridView.Columns.Remove("DONGIA");
                    cthd3DataGridView.Columns.Remove("GIAMGIA");
                    cthd3DataGridView.Columns.Remove("THANHTIEN");
                    //cthd3DataGridView.Columns.Remove("colmasp");
                }
                cthd3DataGridView.Refresh();
            }
            /*Xoá hoá đơn và chi tiết hoá đơn*/
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 3)
            {
                MessageBox.Show("Xoá nè hihi");
                if (txthoadon.Text == "")
                {
                    MessageBox.Show("Vui lòng chọn hoá đơn cần xoá.");
                }
                else
                {
                    HOADON     hd   = new HOADON();
                    CHITIET_HD cthd = new CHITIET_HD();

                    hd   = BH.HOADONs.Where(s => s.MAHD == txthoadon.Text).Single();
                    cthd = BH.CHITIET_HDs.Where(s => s.MAHD == txthoadon.Text).Single();
                    BH.CHITIET_HDs.DeleteOnSubmit(cthd);
                    BH.HOADONs.DeleteOnSubmit(hd);
                    BH.SubmitChanges();
                    loaddulieu();
                    txtghichu.Text       = "";
                    txthoadon.Text       = "";
                    txtkhachang.Text     = "";
                    txtsdt.Text          = "";
                    txttienkhachdua.Text = "";
                    txttientralai.Text   = "";
                    txttongtien.Text     = "";
                    cmbngaylap.Text      = "";
                    MessageBox.Show("Xoá thành công.");
                    // gridhanghoa.Enabled = false;
                    //cmbloaisp.Text = "";
                    //cmbnhacungcap.Text = "";
                    //ptanh.Image = null;
                }
            }
        }