Exemplo n.º 1
0
        private void btnluu_Click(object sender, EventArgs e)
        {
            if (dgvDichvu.Rows.Count == 0)
            {
                MessageBox.Show("Chưa có thông tin để lưu");
                return;
            }
            using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
            {
                HoaDon hd = quanli.HoaDons.FirstOrDefault(p => p.MaHD == cbHoaDon.Text);
                if (hd == null)
                {
                    hd             = new HoaDon();
                    hd.MaHD        = cbHoaDon.Text;
                    hd.UserName    = null;
                    hd.ThoiGianLap = DateTime.Now.Date;
                    hd.TrangThai   = false;
                    quanli.HoaDons.Add(hd);
                    quanli.SaveChanges();
                }

                else
                {
                    hd.TrangThai = false;
                }
                if (txtuudai.Text != "0")
                {
                    CTUuDai ct = quanli.CTUuDais.FirstOrDefault(p => p.MaHD == cbHoaDon.Text);
                    if (ct != null)
                    {
                        MessageBox.Show("Hóa đơn này đã có ưu đãi");
                        return;
                    }
                    CTUuDai ud = new CTUuDai();
                    ud.MaHD = cbHoaDon.Text;
                    ud.MaUD = maud;
                    Console.WriteLine(maud);
                    quanli.CTUuDais.Add(ud);
                    quanli.SaveChanges();
                }
                foreach (DataGridViewRow rows in dgvDichvu.Rows)
                {
                    string madichvu = rows.Cells["madichvu"].Value.ToString();

                    int      sl = int.Parse(rows.Cells["soluong"].Value.ToString());
                    CTDichVu ct = new CTDichVu();
                    ct.MaHD = cbHoaDon.Text;
                    ct.MaDV = madichvu;
                    ct.SoDV = sl;
                    quanli.CTDichVus.Add(ct);
                    quanli.SaveChanges();
                }
                MessageBox.Show("Lưu thành công!");
                loadhdchuathanhtoan();
                btnthem.Enabled      = false;
                btnluu.Enabled       = false;
                btnthanhtoan.Enabled = true;
                return;
            }
        }
Exemplo n.º 2
0
        private void btnluu_Click(object sender, EventArgs e)
        {
            if (dgvThucPham.Rows.Count == 0)
            {
                MessageBox.Show("Chưa có thông tin để lưu");
                return;
            }
            using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
            {
                HoaDon hd = quanli.HoaDons.FirstOrDefault(p => p.MaHD == txtmahoadon.Text);
                if (hd != null)
                {
                    List <CTTHUCPHAM> ds_cttp = quanli.CTTHUCPHAMs.Where(p => p.MaHD == txtmahoadon.Text).ToList();
                    foreach (var item in ds_cttp)
                    {
                        quanli.CTTHUCPHAMs.Remove(item);
                        quanli.SaveChanges();
                    }
                }
                else
                {
                    hd             = new HoaDon();
                    hd.MaHD        = txtmahoadon.Text;
                    hd.UserName    = "******";
                    hd.ThoiGianLap = DateTime.Now.Date;
                    hd.TrangThai   = false;
                    hd.MaUD        = maud;
                    quanli.HoaDons.Add(hd);
                    quanli.SaveChanges();
                }
                if (txtuudai.Text != "0")
                {
                    CTUuDai ud = new CTUuDai();
                    ud.MaHD = txtmahoadon.Text;
                    ud.MaUD = maud;
                    Console.WriteLine(maud);
                    quanli.CTUuDais.Add(ud);
                    quanli.SaveChanges();
                }

                foreach (DataGridViewRow rows in dgvThucPham.Rows)
                {
                    CTTHUCPHAM ct          = new CTTHUCPHAM();
                    string     matp        = rows.Cells["mathucpham"].Value.ToString();
                    string     tenthucpham = rows.Cells["tenthucpham"].Value.ToString();
                    int        sl          = int.Parse(rows.Cells["soluong"].Value.ToString());
                    ct.MaHD        = txtmahoadon.Text;
                    ct.Mathucpham  = matp;
                    ct.Tenthucpham = tenthucpham;
                    ct.soluong     = sl;
                    quanli.CTTHUCPHAMs.Add(ct);
                    quanli.SaveChanges();
                }

                MessageBox.Show("Lưu thành công!");
                loadhdchuathanhtoan();
                btnluu.Enabled       = false;
                btnthem.Enabled      = false;
                btnthanhtoan.Enabled = true;
                return;
            }
        }
Exemplo n.º 3
0
        private void btnluu_Click(object sender, EventArgs e)
        {
            if (dgvThuCung.Rows.Count == 0)
            {
                return;
            }
            try
            {
                using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
                {
                    HoaDon hd = quanli.HoaDons.FirstOrDefault(p => p.MaHD == txtmahoadon.Text);
                    if (hd != null)
                    {
                        List <CTHoaDon> ds_cttc = quanli.CTHoaDons.Where(p => p.MaHD == txtmahoadon.Text).ToList();
                        foreach (var item in ds_cttc)
                        {
                            quanli.CTHoaDons.Remove(item);
                            quanli.SaveChanges();
                        }
                    }
                    else
                    {
                        hd             = new HoaDon();
                        hd.MaHD        = txtmahoadon.Text;
                        hd.UserName    = "******";
                        hd.ThoiGianLap = DateTime.Now.Date;
                        hd.MaKH        = cbkh.SelectedValue.ToString();
                        hd.TrangThai   = false;
                        hd.MaUD        = maud;
                        quanli.HoaDons.Add(hd);
                        quanli.SaveChanges();
                    }


                    if (txtuudai.Text != "0")
                    {
                        CTUuDai ud = new CTUuDai();
                        ud.MaHD = txtmahoadon.Text;
                        ud.MaUD = maud;
                        Console.WriteLine(maud);
                        quanli.CTUuDais.Add(ud);
                        quanli.SaveChanges();
                    }
                    foreach (DataGridViewRow rows in dgvThuCung.Rows)
                    {
                        CTHoaDon ct    = new CTHoaDon();
                        string   matc  = rows.Cells["mathucung"].Value.ToString();
                        string   tentc = rows.Cells["tenthucung"].Value.ToString();
                        int      sl    = int.Parse(rows.Cells["soluong"].Value.ToString());
                        ct.MaHD       = txtmahoadon.Text;
                        ct.MaThuCung  = matc;
                        ct.tenthucung = tentc;
                        ct.SoLuong    = sl;
                        quanli.CTHoaDons.Add(ct);
                        quanli.SaveChanges();
                    }
                    MessageBox.Show("Lưu thành công!");
                    loadhdchuathanhtoan();
                    btnluu.Enabled       = false;
                    btnthanhtoan.Enabled = true;
                    btnthem.Enabled      = false;
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể lưu thông tin vì lý do nào đó. Vui lòng kiểm tra lại");
                return;
            }
        }