Ejemplo n.º 1
0
        protected void btnTaoHoaDon_Click1(object sender, EventArgs e)
        {
            if (rbKHThanhVien.Checked == true)
            {
                //ClientScript.RegisterStartupScript(this.GetType(), "Notification", "Đã tạo hóa đơn thành công", true);
                foreach (GridViewRow row in gvKHThanhVien.Rows)
                {
                    RadioButton rbSelected = (RadioButton)row.FindControl("rbSelectedKH");
                    if (rbSelected.Checked)
                    {
                        string    tienCCK   = lbTongTienCCKValue.Text; tienCCK = tienCCK.Trim(new char[] { ' ', ',', 'V', 'N', 'D' });
                        string    tienSCK   = lbTongTienValue.Text; tienSCK = tienSCK.Trim(new char[] { ' ', ',', 'V', 'N', 'D' });
                        int       chietkhau = int.Parse(tienCCK) - int.Parse(tienSCK);
                        HoaDonDAL hoadon    = new HoaDonDAL();
                        hoadon.AddHoaDon(int.Parse(ngYear.Text), int.Parse(ngMonth.Text), int.Parse(ngDay.Text), int.Parse(nlpYear.Text), int.Parse(nlpMonth.Text), int.Parse(nlpDay.Text), chietkhau, int.Parse(row.Cells[0].Text));
                        DataTable lastestbill = new DataTable();
                        lastestbill = hoadon.RetrieveLastMaHD();
                        string maHD = lastestbill.Rows[0][0].ToString();
                        foreach (GridViewRow tbrow in gvSelectedItemBill.Rows)
                        {
                            hoadon.AddCTHD(int.Parse(tbrow.Cells[0].Text), int.Parse(maHD), int.Parse(tbrow.Cells[3].Text));
                        }
                        //ClientScript.RegisterStartupScript(this.GetType(), "Notification", "Đã tạo hóa đơn thành công", true);

                        /*KhachHangDTO._makh = int.Parse(row.Cells[0].Text);
                         * KhachHangDTO._tenkh = row.Cells[1].Text;
                         * KhachHangDTO._diachi = row.Cells[2].Text;
                         * KhachHangDTO._sdt = row.Cells[3].Text;
                         * string queryString = "FormHoaDon.aspx";
                         * string newWin = "window.open('" + queryString + "');";
                         * ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true);*/
                    }
                }
            }
            else
            {
                KhachHangDAL addKhachHang = new KhachHangDAL();
                int          maKHMoi      = addKhachHang.themKHVangLai(txbTenKHMoi.Text, txbDiaChiKHMoi.Text, txbSDT.Text);
                string       tienCCK      = lbTongTienCCKValue.Text; tienCCK = tienCCK.Trim(new char[] { ' ', ',', 'V', 'N', 'D' });
                string       tienSCK      = lbTongTienValue.Text; tienSCK = tienSCK.Trim(new char[] { ' ', ',', 'V', 'N', 'D' });
                int          chietkhau    = int.Parse(tienCCK) - int.Parse(tienSCK);
                HoaDonDAL    hoadon       = new HoaDonDAL();
                hoadon.AddHoaDon(int.Parse(ngYear.Text), int.Parse(ngMonth.Text), int.Parse(ngDay.Text), int.Parse(nlpYear.Text), int.Parse(nlpMonth.Text), int.Parse(nlpDay.Text), chietkhau, maKHMoi);
                DataTable lastestbill = new DataTable();
                lastestbill = hoadon.RetrieveLastMaHD();
                string maHD = lastestbill.Rows[0][0].ToString();
                foreach (GridViewRow tbRow in gvSelectedItemBill.Rows)
                {
                    hoadon.AddCTHD(int.Parse(tbRow.Cells[0].Text), int.Parse(maHD), int.Parse(tbRow.Cells[3].Text));
                }
                ClientScript.RegisterStartupScript(this.GetType(), "Notification", "Đã tạo hóa đơn thành công", true);
            }
        }