protected void btnPrintPMH_Click(object sender, EventArgs e) { if (dropNhaCC.SelectedValue != "0") { dalPDN dal = new dalPDN(); lblThongbaoReport.Text = ""; string ZSBH = dropNhaCC.SelectedValue.ToString(); string maphieu = Session["maphieu"].ToString(); string macongty = Session["congty"].ToString(); string manguoidung = Session["user"].ToString(); string DDBH = txtDDBH.Text.Trim(); DataTable dtDem = dal.DemMaDatMuaHang(); string abc = dtDem.Rows[0]["CGNO"].ToString(); Int64 NCGNO = Int64.Parse(abc) + 1; string CGNO = NCGNO.ToString(); DateTime date = DateTime.Today; DataTable dtt = dal.TimCGNOTrongBangPDNAS(macongty, maphieu, ZSBH); if (dtt.Rows.Count > 0) { string CG = dtt.Rows[0]["CGNO"].ToString(); if (CG == null) { dal.CapNhatCGNOTrongBangPDNAS(macongty, maphieu, CGNO, ZSBH); dal.ThemCGNOTrongBangCGZL(macongty, CGNO, ZSBH, manguoidung); DataTable dt = dal.TimMaDonDatHangTheoNhaCungUngVaSoPhieuNoSize(macongty, maphieu, ZSBH); if (dt.Rows.Count != 0) { if (dropTypePrint.SelectedValue == "1") { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangNoSize&maphieu=" + maphieu + "&CGNO=" + CGNO + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } else { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangNoSizeNoTitle&maphieu=" + maphieu + "&CGNO=" + CGNO + "&macongty=" + macongty + "&ZSBH=" + ZSBH); //Response.Redirect("ReportPhieuMuaHang.aspx?Type=PhieuDatMuaHangNoSizeNoTitle&maphieu=" + maphieu + "&CGNO=" + CGNO + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } } else { DataTable dtSize = dal.TimMaDonDatHangTheoNhaCungUngVaSoPhieuSize(macongty, maphieu, ZSBH); if (dtSize.Rows.Count != 0) { if (DDBH != "") { DataTable kiemtr = dal.KiemTraDDBHTrongBangDDZL(DDBH); if (kiemtr.Rows.Count > 0) { foreach (DataRow dr in dtSize.Rows) { dal.CapNhatDDBHTrongBangPDNAS(macongty, maphieu, DDBH, ZSBH); } //DataTable dtp = dal.TimKiemCLBHTrongBangPDNAS(maphieu, macongty, ZSBH, CGNO); //if (dtp.Rows.Count > 0) //{ // foreach (DataRow dr in dtp.Rows) // { // string CLBH = dr["CLBH"].ToString(); // decimal Qty = decimal.Parse(dr["Qty"].ToString()); // dal.ThemCGNOTrongBangCGZLS(macongty, CGNO, CLBH, manguoidung, Qty); // } //} if (dropTypePrint.SelectedValue == "1") { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangSize&maphieu=" + maphieu + "&CGNO=" + CGNO + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } else { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangSizeNoTitle&maphieu=" + maphieu + "&CGNO=" + CGNO + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } } else { lblThongbaoReport.Text = "DDBH Incorrect,please try again!"; } } } } }// da co CGNO else { DataTable dt = dal.TimMaDonDatHangTheoNhaCungUngVaSoPhieuNoSize(macongty, maphieu, ZSBH); if (dt.Rows.Count != 0) { if (dropTypePrint.SelectedValue == "1") { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangNoSize&maphieu=" + maphieu + "&CGNO=" + CG + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } else { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangNoSizeNoTitle&maphieu=" + maphieu + "&CGNO=" + CG + "&macongty=" + macongty + "&ZSBH=" + ZSBH); //Response.Redirect("ReportPhieuMuaHang.aspx?Type=PhieuDatMuaHangNoSizeNoTitle&maphieu=" + maphieu + "&CGNO=" + CGNO + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } } else { DataTable dtSize = dal.TimMaDonDatHangTheoNhaCungUngVaSoPhieuSize(macongty, maphieu, ZSBH); if (dtSize.Rows.Count != 0) { if (DDBH != "") { DataTable kiemtr = dal.KiemTraDDBHTrongBangDDZL(DDBH); if (kiemtr.Rows.Count > 0) { foreach (DataRow dr in dtSize.Rows) { dal.CapNhatDDBHTrongBangPDNAS(macongty, maphieu, DDBH, ZSBH); } //DataTable dtp = dal.TimKiemCLBHTrongBangPDNAS(maphieu, macongty, ZSBH, CGNO); //if (dtp.Rows.Count > 0) //{ // foreach (DataRow dr in dtp.Rows) // { // string CLBH = dr["CLBH"].ToString(); // decimal Qty = decimal.Parse(dr["Qty"].ToString()); // dal.ThemCGNOTrongBangCGZLS(macongty, CGNO, CLBH, manguoidung, Qty); // } //} if (dropTypePrint.SelectedValue == "1") { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangSize&maphieu=" + maphieu + "&CGNO=" + CG + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } else { Response.Redirect("WF_ReportPDN.aspx?Type=PhieuDatMuaHangSizeNoTitle&maphieu=" + maphieu + "&CGNO=" + CG + "&macongty=" + macongty + "&ZSBH=" + ZSBH); } } else { lblThongbaoReport.Text = "DDBH Incorrect,please try again!"; } } } } } } } }