protected void Button1_Click(object sender, EventArgs e) { string date = Convert.ToDateTime(txt_ngaySinh.Text).ToString("yyyy-MM-dd"); DateTime sdate = Convert.ToDateTime(date); int ngay = int.Parse(sdate.Day.ToString()); int thang = int.Parse(sdate.Month.ToString()); int nam = int.Parse(sdate.Year.ToString()); string sql = "Select*from tbTHONGTINCANHAN where KH_ID='" + makh() + "'"; dt = cs.getTable(sql); string q; string data; if (dt.Rows.Count > 0) { q = "Update tbTHONGTINCANHAN set HoTen= N'" + txt_TenKhachHang.Text + "',NgaySinh='" + nam + " / " + thang + " / " + ngay + "',GioiTinh_ID='" + drop_gioitinh.SelectedValue.ToString() + "',SoDienThoai='" + txt_DienThoai.Text + "',Email='" + txt_Email.Text + "',DiaChi= N'" + txt_DiaChi.Text + "', SoThich_ID ='" + dropdown_Sothich.SelectedValue.ToString() + "',ThuNhap_ID='" + drp_thunhap.SelectedValue.ToString() + "' where KH_ID ='" + makh() + "'"; cs.ExecuteNonQuery(q); data = "Update tbLOGIN set Password='******' where User_ID='" + makh() + "'"; cs.ExecuteNonQuery(data); } else { q = "Insert into tbTHONGTINCANHAN(HoTen,NgaySinh,GioiTinh_ID,SoDienThoai,Email,DiaChi,SoThich_ID,ThuNhap_ID)values(N'" + txt_TenKhachHang.Text + "','" + nam + " / " + thang + " / " + ngay + "','" + drop_gioitinh.SelectedValue.ToString() + "','" + txt_DienThoai.Text + "','" + txt_Email.Text + "', N'" + txt_DiaChi.Text + "','" + dropdown_Sothich.SelectedValue.ToString() + "','" + drp_thunhap.SelectedValue.ToString() + "')"; cs.ExecuteNonQuery(q); } Response.Redirect("/ThongTinKhachHang.aspx"); }
protected void btn_dangky_Click(object sender, EventArgs e) { try { string Tendangnhap = username.Value.ToString(); string Matkhau = password1.Value.ToString(); string Xacnhan_matkhau = password2.Value.ToString(); string Hoten = hoten.Value.ToString(); string sql = "Select * from tbLOGIN where UserName ='******'"; DataTable dt = cm.getTable(sql); string ten = ""; foreach (DataRow row in dt.Rows) { ten += row["UserName"].ToString(); } if (dt.Rows.Count > 0) { string script = "alert(\"Đã có tên đăng nhập này!\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); return; } else { if (Matkhau.Equals(Xacnhan_matkhau) == false) { string script = "alert(\"Nhập sai mật khẩu ở xác nhận mật khẩu!\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); return; } else { string q = "Insert into tbLOGIN(UserName,Password,Group_ID) values('" + Tendangnhap + "','" + MaHoaMD5.Encryptdata(Matkhau) + "',1)"; cm.ExecuteNonQuery(q); string data = "Select * from tbLOGIN where UserName='******' and Password='******'"; DataTable tb = cm.getTable(data); string user_id = tb.Rows[0]["User_ID"].ToString(); int ngay = int.Parse(day.Value.ToString()); int thang = int.Parse(month.Value.ToString()); int nam = int.Parse(year.Value.ToString()); string q1 = "Insert into tbTHONGTINCANHAN(KH_ID,HoTen,NgaySinh,Email)values('" + user_id + "',N'" + Hoten + "','" + nam + "/" + thang + "/" + ngay + "','" + email.Value.ToString() + "')"; cm.ExecuteNonQuery(q1); string script = "alert(\"Mời bạn đăng nhập!\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); Response.Redirect("DanhSachMatHang.aspx"); } } } catch (SqlException ex) { throw ex; } }
protected void Button1_Click(object sender, EventArgs e) { try { string Tendangnhap = tendangnhap.Value.ToString(); string Matkhau = MaHoaMD5.Encryptdata(matkhau.Value.ToString()); string Xacnhan_matkhau = MaHoaMD5.Encryptdata(xacnhan_matkhau.Value.ToString()); string Hoten = txt_hoten.Value.ToString(); string sql = "Select * from tbLOGIN"; dt = cs.getTable(sql); string ten = ""; foreach (DataRow row in dt.Rows) { ten += row["UserName"].ToString(); } if (Tendangnhap == ten) { string script = "alert(\"Đã có tên đăng nhập này!\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); } else { if (Matkhau.Equals(Xacnhan_matkhau) == false) { string script = "alert(\"Nhập sai mật khẩu ở xác nhận mật khẩu!\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); return; } else { string q = "Insert into tbLOGIN(UserName,Password,Group_ID) values('" + Tendangnhap + "','" + Matkhau + "',1)"; cs.ExecuteNonQuery(q); string data = "Select * from tbLOGIN where UserName='******' and Password='******'"; DataTable tb = cs.getTable(data); string user_id = ""; foreach (DataRow row in tb.Rows) { user_id = row["User_ID"].ToString(); } string q1 = "Insert into tbTHONGTINCANHAN(KH_ID,HoTen)values('" + user_id + "',N'" + Hoten + "')"; cs.ExecuteNonQuery(q1); string script = "alert(\"Mời bạn đăng nhập!\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); Response.Redirect("DangNhap.aspx"); } } } catch (SqlException ex) { throw ex; } }
protected void btn_save_Click(object sender, EventArgs e) { string sql = "Update tbLOGIN set Group_ID='" + dropdown_group.SelectedValue.ToString() + "' where User_ID='" + Text1.Value.ToString() + "'"; cm.ExecuteNonQuery(sql); Server.Transfer("QuanLyTaiKhoan.aspx"); }
protected void btn_xoa_sp_Click(object sender, EventArgs e) { string masp = ((LinkButton)sender).CommandArgument; string sql = "Delete from tbSANPHAM where SanPham_ID='" + masp + "'"; cm.ExecuteNonQuery(sql); docDL_Spham(); }
protected void btn_save_Click(object sender, EventArgs e) { string danhmuccon = txt_tendanhmuccon.Value.ToString(); string sql = "Insert into tbDANHMUC(TenDanhMuc,Parent_ID)values(N'" + danhmuccon + "','" + drp_danhmuccha.SelectedValue.ToString() + "')"; cm.ExecuteNonQuery(sql); Response.Redirect("QLDanhMuc.aspx"); }
protected void btn_themDMCha_Click(object sender, EventArgs e) { string DMCha = danhmuccha.Value.ToString(); string sql = "Insert into tbDANHMUC(TenDanhMuc,Parent_ID) values(N'" + DMCha + "',0)"; cm.ExecuteNonQuery(sql); docDL(); }
protected void btn_xoa_Click(object sender, EventArgs e) { string user_id = ((LinkButton)sender).CommandArgument; if (Int16.Parse(user_id) != 2) { string sql = "Delete from tbTHONGTINCANHAN where KH_ID='" + user_id + "'"; cm.ExecuteNonQuery(sql); string data = "Delete from tbLOGIN where User_ID='" + user_id + "'"; cm.ExecuteNonQuery(data); } else { string sql2 = "Delete from tbTHONGTINCANHAN where KH_ID='" + user_id + "'"; cm.ExecuteNonQuery(sql2); string data = "Select * from tbUSER_GROUP where User_ID='" + user_id + "'"; DataTable tb = cm.getTable(data); int user_group_id = Int16.Parse(tb.Rows[0]["User_Group_ID"].ToString()); string sql_gr_md = "Delete from tbUSER_GROUP_MODULE where User_Group_ID=" + user_group_id + ""; cm.ExecuteNonQuery(sql_gr_md); string sql1 = "Delete from tbUSER_GROUP where User_ID='" + user_id + "'"; cm.ExecuteNonQuery(sql1); string sql = "delete from tbLOGIN where User_ID='" + user_id + "'"; cm.ExecuteNonQuery(sql); } docDL(); }
protected void btn_save_Click(object sender, EventArgs e) { string tensp = txt_tensp.Value.ToString(); float dongia = float.Parse(txt_dongia.Value.ToString()); int soluong = Int16.Parse(txt_soluong.Value.ToString()); string mota = txt_mota.Value.ToString(); string mau_id = drp_mau.SelectedItem.Value.ToString(); string danhmuc_id = drp_DanhMuc.SelectedItem.Value.ToString(); string sql = "Update tbSANPHAM set TenSanPham=N'" + tensp + "',DonGia=" + dongia + ",SoLuong=" + soluong + ",MoTa='" + mota + "',Mau_ID='" + mau_id + "',DanhMuc_ID='" + danhmuc_id + "' where SanPham_ID='" + txt_spid.Value + "'"; cm.ExecuteNonQuery(sql); Server.Transfer("QLSanPham.aspx"); }
protected void btn_save_Click(object sender, EventArgs e) { if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0)) { if (CheckFileType(FileUpload1.FileName)) { try { string sFolderPath = Server.MapPath(@"/images/AnhDT"); HttpPostedFile myFile = FileUpload1.PostedFile; string sFileName = myFile.FileName; myFile.SaveAs( string.Format(@"{0}\{1}", sFolderPath, sFileName)); string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName); hinhanh = sFileName; lblthongbao.Text = "Upload ảnh thành công!"; string tensp = txt_tensanpham.Value.ToString(); float dongia = float.Parse(txt_dongia.Value.ToString()); int soluong = Int16.Parse(txt_soluong.Value.ToString()); string mota = txt_mota.Value.ToString(); string mau = drp_mau.SelectedItem.Value.ToString(); string danhmuc = dropdown_group.SelectedItem.Value.ToString(); string sql = "Insert INTO tbSANPHAM(TenSanPham,DonGia,HinhAnh,SoLuong,MoTa,Mau_ID,DanhMuc_ID)values(N'" + tensp + "'," + dongia + ",'" + hinhanh + "'," + soluong + ",N'" + mota + "','" + mau + "','" + danhmuc + "')"; cm.ExecuteNonQuery(sql); Response.Redirect("QLSanPham.aspx"); } catch (Exception ex) { Response.Write("Error: " + ex.Message); //Note: Exception.Message returns a detailed message that describes the current exception. //For security reasons, we do not recommend that you return Exception.Message to end users in //production environments. It would be better to put a generic error message. } } else { lblthongbao.Text = "Không đúng file.jpg!"; } } else { lblthongbao.Text = ("Làm ơn chọn file!"); } }
protected void btn_DatHang_Click(object sender, EventArgs e) { string username = Request.Cookies["UserName"].Value; string password = Request.Cookies["Password"].Value; string userid = "Select User_ID from tbTHONGTINCANHAN,tbLOGIN where UserName='******' and Password='******' and tbTHONGTINCANHAN.KH_ID=tbLOGIN.User_ID"; DataTable tb = cs.getTable(userid); string makh = ""; foreach (DataRow row in tb.Rows) { makh = row["User_ID"].ToString(); } if (Session["tbGiohang"] == null) { Response.Redirect("GioHang.aspx"); } dt = (DataTable)Session["tbGiohang"]; double tong = 0; for (int i = 0; i < dt.Rows.Count; i++) { double thanhtien = Convert.ToDouble(dt.Rows[i]["SoLuong"]) * Convert.ToDouble(dt.Rows[i]["DonGia"]); dt.Rows[i]["ThanhTien"] = Math.Round(thanhtien) + ""; tong += thanhtien; } int ngay = int.Parse(DateTime.Now.Day.ToString()); int thang = int.Parse(DateTime.Now.Month.ToString()); int nam = int.Parse(DateTime.Now.Year.ToString()); string sql1 = "Insert into tbHOADON(User_ID,TenKhachHang,DiaChi,Phone,NgayHD,TongTien,Pay_ID,Status) values('" + makh + "',N'" + txt_TenKhachHang.Text + "',N'" + txt_DiaChi.Text + "','" + txt_DienThoai.Text + "','" + nam + " / " + thang + " / " + ngay + "'," + tong + ",'" + dropdown_thanhtoan.SelectedItem.Value.ToString() + "',0)"; cs.ExecuteNonQuery(sql1); string sql2 = "select HD_ID from tbHOADON"; int idDH = 0; foreach (DataRow r in cs.getTable(sql2).Rows) { idDH = int.Parse(r[0].ToString()); } if (dt.Rows.Count > 0) { foreach (DataRow r in dt.Rows) { int idSP = int.Parse(r["SanPham_ID"].ToString()); int SoLuong = int.Parse(r["SoLuong"].ToString()); double Gia = double.Parse(r["DonGia"].ToString()); string mau = r["TenMau"].ToString(); string hinhanh = r["HinhAnh"].ToString(); string sql3 = "insert into tbCHITIETHOADON(HD_ID,SanPham_ID,HinhAnh,DonGia,Mau,SoLuongDat) values(" + idDH + "," + idSP + ",'" + hinhanh + "'," + Gia + ",N'" + mau + "'," + SoLuong + ")"; cs.ExecuteNonQuery(sql3); } } //string return_url = "http://*****:*****@dotnet.vn";//Tài khoản nhận tiền //String price = tong.ToString(); //Checkout nl = new Checkout(); //String url; //url = nl.buildCheckoutUrl(return_url, receiver, transaction_info, order_code, price); //Response.Redirect(url); Response.Redirect("DatHangThanhCong.aspx"); }