コード例 #1
0
 protected void btDongY_Click(object sender, EventArgs e)
 {
     try
     {
         DataTable dt = x.GetData("Select TenDN From KHACHHANG where TenDN='" + txtTenDN.Text + "' and MatKhau='" + txtMatKhauCu.Text + "'");
         if (dt.Rows.Count > 0)
         {
             /*
              * SqlConnection con = new SqlConnection(x.strCon);
              * con.Open();
              * SqlCommand cmd = new SqlCommand();
              * cmd.CommandType = CommandType.Text;
              * cmd.Connection = con;
              * cmd.CommandText = @"UPDATE KhachHang Set MatKhau=@MatKhau WHERE TenDN = @TenDN";
              * cmd.Parameters.Add("@TenDN", SqlDbType.VarChar, 15);
              * cmd.Parameters["@TenDN"].Value = txtTenDN.Text;
              * cmd.Parameters.Add("@MatKhau", SqlDbType.VarChar, 15);
              * cmd.Parameters["@MatKhau"].Value = txtMatKhauMoi.Text;
              * cmd.ExecuteNonQuery();
              * con.Close();
              */
             x.Execute("UPDATE KhachHang Set MatKhau = '" + txtMatKhauMoi.Text + "' WHERE TenDN = '" + txtTenDN.Text + "'");
             lbThongBaoLoi.Text = "Đổi mật khẩu thành công";
         }
         else
         {
             lbThongBaoLoi.Text = "Tên đăng nhập hoặc mật khẩu cũ không hợp lệ!";
         }
     }
     catch
     {
         lbThongBaoLoi.Text = "Thất bại!";
     }
 }
コード例 #2
0
    protected void btDongY_Click(object sender, EventArgs e)
    {
        //Luu du lieu vao database
        int    httt, htgh;
        string TenNguoiNhan, DiaChiNhan, DienThoaiNhan;

        //Gán giá trị cho các bien
        TenNguoiNhan  = txtTenNguoiNhan.Text;
        DiaChiNhan    = txtDiaChiNhan.Text;
        DienThoaiNhan = txtDienThoaiNhan.Text;
        //string Ngaydathang = DateTime.Today.ToString();
        //string Ngaygiao = CalendarNgaygiaohang.SelectedDate.ToString();
        float tongThanhTien = float.Parse(lbTongTien.Text);

        httt = Convert.ToInt32(rblHinhThucThanhToan.SelectedItem.Value);
        htgh = Convert.ToInt32(rblHinhThucGiaoHang.SelectedItem.Value);
        try
        {
            //string s = @"INSERT INTO Dondathang(MaKH,NgayDH,Ngaygiaohang,Tennguoinhan,Diachinhan,Dienthoainhan,HTThanhtoan,HTGiaohang,Trigia) VALUES(" + MaKH + ",'" + Ngaydathang + "','" + Ngaygiao + "','" + Tennguoinhan + "','" + Diachinhan + "','" + Dienthoainhan + "'," + httt + "," + htgh + "," + tongThanhTien + ")";
            //x.Execute(s);

            SqlConnection con = new SqlConnection(x.strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = con;

            cmd.CommandText = @"INSERT INTO DONDATHANG(MaKH,NgayDH,TriGia,NgayGiaoHang,TenNguoiNhan,DiaChiNhan,DienThoaiNhan,HTThanhToan,HTGiaoHang) Values(" + MaKH + ",@ngaydathang," + tongThanhTien + ",@ngaygiaohang,N'" + TenNguoiNhan + "','" + DiaChiNhan + "','" + DienThoaiNhan + "'," + httt + "," + htgh + ")";
            cmd.Parameters.Add("@ngaydathang", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngaydathang"].Value = DateTime.Today;
            cmd.Parameters.Add("@ngaygiaohang", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngaygiaohang"].Value = cldNgayGiaoHang.SelectedDate;

            cmd.ExecuteNonQuery();

            con.Close();

            //Lay SoDH vua nhap sau cung
            string    s         = "Select max(SoDH) from DONDATHANG Where MaKH=" + MaKH;
            int       SoDonHang = int.Parse(x.GetData(s).Rows[0][0].ToString());
            DataTable dt        = new DataTable();
            dt = (DataTable)Session["Giohang"];

            int   MaHoa, SoLuong;
            float DonGia;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MaHoa   = int.Parse(dt.Rows[i]["MaHoa"].ToString());
                SoLuong = int.Parse(dt.Rows[i]["SoLuong"].ToString());
                DonGia  = float.Parse(dt.Rows[i]["DonGia"].ToString());
                s       = "INSERT INTO CTDATHANG(SoDH,MaHoa,SoLuong,DonGia) VALUES(" + SoDonHang + "," + MaHoa + "," + SoLuong + "," + DonGia + ")";
                x.Execute(s);
            }

            Session["Giohang"] = null; //Xóa giỏ hàng sau khi đã thực hiện xong đặt hàng
            Response.Redirect("~/Xacnhandonhang.aspx?tt=1");
        }
        catch
        {
            lbThongBaoLoi.Text = "Lỗi trong quá trình cập nhật dữ liệu!";
        }
    }