protected void xuathd_Click(object sender, EventArgs e)
 {
     if (Request.QueryString["mapn"] != null)
     {
         int      ma = int.Parse(Request.QueryString["mapn"].ToString());
         Redirect rd = new Redirect();
         rd.ChuyenTrang("inhoadon.aspx?xuatpn=" + ma, "_blank", "");
     }
 }
Ejemplo n.º 2
0
 protected void btnLuu_Click(object sender, EventArgs e)
 {
     if (Session["cthd"] != null)
     {
         string    sql = "select MaKH from KhachHang where SDT='" + Session["sdt"].ToString() + "'";
         DataTable dt;
         dt = kn.GetData(sql);
         if (dt.Rows.Count > 0)
         {
             int makh = int.Parse(dt.Rows[0][0].ToString());
             try
             {
                 kn.Execute("update KhachHang set TenKH=N'" + Session["tenkh"].ToString().Trim() + "' where MaKH=" + makh);
                 themHD_CTHD(dt);
                 string sqlHD = "select Max(MaHD) from R_HoaDon where SDT='" + Session["sdt"].ToString() + "'";
                 dt = kn.GetData(sqlHD);
                 if (dt.Rows.Count > 0)
                 {
                     gvCTHD.Visible       = false;
                     btnHuy.Visible       = false;
                     btncapnhat.Visible   = false;
                     btnLuu.Visible       = false;
                     lbltc.Visible        = false;
                     lblthanhtien.Visible = false;
                     txtmakh.Enabled      = true;
                     txttenkh.Enabled     = true;
                     txttenkh.Text        = "";
                     txtmakh.Text         = "";
                     Redirect rd = new Redirect();
                     //     rd.ChuyenTrang("themhoadon.aspx", "", "");
                     rd.ChuyenTrang("inhoadon.aspx?xuathd=" + int.Parse(dt.Rows[0][0].ToString()), "_blank", "");
                 }
             }
             catch
             {
                 Response.Write("<script> alert('Đã xảy ra lỗi. Vui lòng kiểm tra lại.') </script>");
             }
         }
         else
         {
             try
             {
                 SqlConnection conKH = new SqlConnection(kn.chuoiketnoi);
                 conKH.Open();
                 SqlCommand cmdKH = new SqlCommand();
                 cmdKH.Connection  = conKH;
                 cmdKH.CommandType = CommandType.StoredProcedure;
                 cmdKH.CommandText = "Proc_ThemKH";
                 cmdKH.Parameters.Add("@TenKH", SqlDbType.NVarChar, 50).Value = Session["tenkh"].ToString().Trim();
                 cmdKH.Parameters.Add("@SDT", SqlDbType.VarChar, 10).Value    = Session["sdt"].ToString().Trim();
                 cmdKH.Parameters.Add("@Email", SqlDbType.VarChar, 100).Value = "";
                 cmdKH.ExecuteNonQuery();
                 conKH.Close();
                 dt = kn.GetData(sql);
                 themHD_CTHD(dt);
                 string sqlHD = "select Max(MaHD) from R_HoaDon where SDT='" + Session["sdt"].ToString() + "'";
                 dt = kn.GetData(sqlHD);
                 if (dt.Rows.Count > 0)
                 {
                     Redirect rd = new Redirect();
                     //  rd.ChuyenTrang("themhoadon.aspx", "", "");
                     rd.ChuyenTrang("inhoadon.aspx?xuathd=" + int.Parse(dt.Rows[0][0].ToString()), "_blank", "");
                 }
             }
             catch
             {
                 Response.Write("<script> alert('Đã xảy ra lỗi. Vui lòng kiểm tra lại.') </script>");
             }
         }
     }
     else
     {
         Response.Redirect("themhoadon.aspx");
     }
     Session["cthd"] = null;
 }