public static bool ValidateCustomerPhone(string cellNumber, string confimKey, Point point) { using (var tran = TransactionManager.Create()) { if (CustomerDA.ValidateCustomerPhone(cellNumber, confimKey) == false) { return(false); } PointFilter filter = new PointFilter { CustomerSysNo = point.CustomerSysNo, ObtainType = point.ObtainType, LanguageCode = ConstValue.LanguageCode, CompanyCode = ConstValue.CompanyCode, CurrencyCode = ConstValue.CurrencySysNo.ToString(), StoreCompanyCode = ConstValue.StoreCompanyCode }; if (CommonDA.ExistsPoint(filter) <= 0) { CommonFacade.AddPoint(point); } tran.Complete(); return(true); } }
public ActionResult GetCustomerInfo(string userName) { var _customerDA = new CustomerDA(); var customer = _customerDA.GetCustomerItemByUserName(userName); return(Json(customer)); }
public OperationResult <CustomerLawyerData> GetCustomerById(RequestOperation <int> request) { var result = new OperationResult <CustomerLawyerData>(); try { var customer = CustomerDA.GetCustomerById(request.Body); if (customer == null) { throw new Exception("不存在该用户"); } result.Body = customer; result.ErrCode = 0; result.Message = "ok"; } catch (Exception ex) { Logger.WriteException("GetCustomerById", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
/// <summary> /// 更改用户密码 /// </summary> /// <param name="customerId">用户Id</param> /// <param name="oldPassword">旧密码</param> /// <param name="newPassword">新密码</param> /// <returns>更新结果</returns> public static bool UpdateCustomerPassword(string customerId, string oldPassword, string newPassword) { var result = CustomerDA.UpdateCustomerPassword(customerId, oldPassword, newPassword); if (result) { //密码修改成功后发送短信 var customer = CustomerFacade.GetCustomerByID(customerId); if (customer.IsPhoneValided == 1) { var sms = new SMSInfo(); sms.CellNumber = customer.CellPhone; sms.CompanyCode = ConstValue.CompanyCode; sms.CreateTime = DateTime.Now; sms.CreateUserSysNo = customer.SysNo; sms.LanguageCode = ConstValue.LanguageCode; sms.Priority = 1; sms.SMSContent = AppSettingManager.GetSetting("SMSTemplate", "AlertUpdatePassword"); sms.Status = SMSStatus.NoSend; sms.StoreCompanyCode = ConstValue.StoreCompanyCode; sms.Type = SMSType.AlertUpdatePassword; sms.RetryCount = 0; CommonDA.InsertNewSMS(sms); } } return(result); }
public HttpResponseMessage Get(string id) { if (string.IsNullOrEmpty(id)) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest } } ; ClaimsPrincipal p = RequestContext.Principal as ClaimsPrincipal; Customer cust = CustomerDA.GetCustomer(Convert.ToInt32(id), p.Claims); if (cust == null) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound } } ; HttpResponseMessage response = new HttpResponseMessage(); HttpContent content = new ObjectContent(typeof(Customer), cust, new JsonMediaTypeFormatter()); response.Content = content; response.StatusCode = HttpStatusCode.OK; return(response); }
public QueryResultList <CustomerSkillData> GetCustomerSkill(RequestOperation request) { var result = new QueryResultList <CustomerSkillData>(); try { var data = CustomerDA.GetCustomerSkill(request); if (data == null) { data = new List <CustomerSkillData>(); } result.Body = data; result.ErrCode = 0; result.Message = "ok"; } catch (Exception ex) { //System.Reflection.MethodInfo.GetCurrentMethod().Name Logger.WriteException("GetCustomerSkill", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public OperationResult SetCustomerSort(RequestOperation <CustomerSortData> request) { var result = new OperationResult(); try { var rows = CustomerDA.SetCustomerSort(request); if (rows <= -1) { result.ErrCode = 1; result.Message = "更新排序失败"; } else { result.ErrCode = 0; result.Message = "ok"; } } catch (Exception ex) { Logger.WriteException("SetCustomerSort", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public OperationResult SeCustomerPwd(RequestOperation <CustomerPwdData> request) { var result = new OperationResult(); try { request.Body.Password = MD5Helper.Encode(request.Body.Password); var rows = CustomerDA.SetCustomerPwd(request); if (rows == 0) { result.ErrCode = 1; result.Message = "设置失败"; } else { result.ErrCode = 0; result.Message = "ok"; } } catch (Exception ex) { Logger.WriteException("SeCustomerPwd", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public bool checkExistingCustomer() { try { CustomerDA cda = new CustomerDA(); DataSet ds = cda.CheckExistingCustomer(); foreach (DataTable DT in ds.Tables) { foreach (DataRow DR in DT.Rows) { if (Convert.ToBoolean(DR[1].ToString())) return true; } } } catch (Exception ex) { } return false; }
public OperationResult SetCustomerStatus(RequestOperation <CustomerStatusData> request) { var result = new OperationResult(); try { var row = CustomerDA.SetCustomerStatus(request); if (row == 0) { result.ErrCode = 1; result.Message = "设置失败"; } else { result.ErrCode = 0; result.Message = "ok"; } } catch (Exception ex) { //System.Reflection.MethodInfo.GetCurrentMethod().Name Logger.WriteException("SetCustomerStatus", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public OperationResult <CustomerLoginData> LoginByAccount(RequestOperation <UserLoginData> request) { var result = new OperationResult <CustomerLoginData>(); try { request.Body.Password = MD5Helper.Encode(request.Body.Password); result.Body = CustomerDA.LoginByAccount(request.Body); if (result.Body == null) { result.ErrCode = 1; result.Message = "用户名或密码错误"; } else { result.ErrCode = 0; result.Message = "ok"; } } catch (Exception ex) { Logger.WriteException("LoginByAccount", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public OperationResult <CustomerLoginData> LoginByWechatAccount(RequestOperation <string> request) { var result = new OperationResult <CustomerLoginData>(); try { result.Body = CustomerDA.LoginByWechatAccount(request); if (result.Body == null) { result.ErrCode = 1; result.Message = "不存在此用户"; } else { if (result.Body.UserStatus != 10) { result.Message = "当前用户被冻结,请联系客服"; return(result); } result.ErrCode = 0; result.Message = "ok"; } } catch (Exception ex) { Logger.WriteException("LoginByWechatAccount", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public void Delete() { var da = new CustomerDA(); //Agregando un registro var entity = new Customer { FirstName = "Maria", LastName = "Romero", Company = "Reprodata", Address = "Av. Simon 123", City = "Lima", State = "Lima", Country = "Perú", PostalCode = "1245", Phone = "4563214", Fax = "46512321", Email = "*****@*****.**", SupportRepId = null }; //entity.Name = "Artist Test"; var id = da.Insert(entity); //Eliminando registro var result = da.Delete(id); Assert.IsTrue(result); }
public static void AdjustCustomerExperience(int customerSysNo, decimal experience, ExperienceLogType type, string memo) { CustomerExperienceLog entity = new CustomerExperienceLog(); entity.CustomerSysNo = customerSysNo; entity.Amount = experience; entity.Memo = memo; entity.Type = type; CustomerBasicInfo customer = GetCustomerInfo(customerSysNo); var totalExperience = customer.TotalExperience.Value; totalExperience = totalExperience + entity.Amount.Value; if (totalExperience < 0) { throw new BusinessException("顾客的最终经验值必须为正值"); } CustomerDA.UpdateExperience(entity.CustomerSysNo.Value, totalExperience); CustomerExperienceLog cuslog = new CustomerExperienceLog(); cuslog.CustomerSysNo = entity.CustomerSysNo; cuslog.Amount = entity.Amount; cuslog.Memo = string.Format("(用户系统号:{0};原值:{1}){2}", entity.CustomerSysNo, totalExperience - cuslog.Amount, entity.Memo); cuslog.Type = entity.Type; CustomerDA.InsertExperienceLog(cuslog); CustomerDA.SetRank(entity.CustomerSysNo.Value); }
protected void btnLogin_Click(object sender, EventArgs e) { string email = txtEmail.Text; string password = txtPassword.Text; Customer c = CustomerDA.GetCustomerByLogin(email); if (c == null) { lblError.Text = "No such email please try again or <a runat='server' href='customerSignUp.aspx'>sign up!</a>"; lblError.Visible = true; } else { if (CustomerDA.VerifyLogin(email, password)) { Session["Customer"] = c; Response.Redirect("~"); } else { lblError.Text = "Incorrect Email/Password try again"; lblError.Visible = true; } } }
public OperationResult <SearchResultData> GetSearchResult(QueryRequest <string> query) { var result = new OperationResult <SearchResultData>(); try { result.Body = new SearchResultData(); result.Body.Articles = ArticleDA.GetArticleByKey(query); if (result.Body.Articles == null) { result.Body.Articles = new List <ArticleShowData>(); } result.Body.Lawyers = CustomerDA.GetCustomerByKey(query); if (result.Body.Lawyers == null) { result.Body.Lawyers = new List <CustomerLawyerShowData>(); } result.ErrCode = 0; result.Message = "ok"; } catch (Exception ex) { Logger.WriteException("GetShowItems", ex, query); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
protected void Page_Load(object sender, EventArgs e) { if (Membership.GetUser() != null && !Page.IsPostBack) { // create customer object to search for Customer customerSearchObject = new Customer(null, null, Membership.GetUser().UserName, null, null, null, null, null, null, null, null); // get current user customer account information from the database CustomerDA customerDA = new CustomerDA(); Collection<Customer> customerInfo = customerDA.GetLike(customerSearchObject); // put the user information into the form lblUserFName.Text = customerInfo[0].FirstName; lblUserLName.Text = customerInfo[0].LastName; lblUserAddress.Text = customerInfo[0].Address; if (customerInfo[0].Address2 != null) lblUserAddress2.Text = customerInfo[0].Address2; lblUserCity.Text = customerInfo[0].City; lblUserState.Text = customerInfo[0].State; lblUserZip.Text = customerInfo[0].Zip; lblUserCountry.Text = customerInfo[0].Country; lblUserEmail.Text = Membership.GetUser().Email; } else { // user not logged in, redirect user to login page if (!Page.IsPostBack) Response.Redirect("Login.aspx"); } }
public HttpResponseMessage Delete(int id) { ClaimsPrincipal p = RequestContext.Principal as ClaimsPrincipal; CustomerDA.DeleteCustomer(id, p.Claims); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public JsonResult Register() { var msg = new JsonMessage { Erros = false, Message = "Đăng ký thành công", }; try { var cus = new Customer(); var da = new CustomerDA(); UpdateModel(cus); cus.DateCreated = DateTime.Now.TotalSeconds(); cus.IsDelete = false; cus.PasswordSalt = FDIUtils.RandomKey(8); cus.PassWord = FDIUtils.Encrypt(cus.PassWord, cus.PasswordSalt); da.Add(cus); da.Save(); } catch (Exception) { msg.Erros = true; msg.Message = "Vui lòng thử lại!"; } return(Json(msg)); }
public HttpResponseMessage Post(Customer c) { ClaimsPrincipal p = RequestContext.Principal as ClaimsPrincipal; CustomerDA.UpdateCustomer(c, p.Claims); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public OperationResult VerifyAccount(RequestOperation <CustomerAccountQueryData> request) { var result = new OperationResult(); try { var row = CustomerDA.VerifyAccount(request); if (row == null || row.UserID <= 0) { result.ErrCode = 0; result.Message = "ok"; } else { result.ErrCode = 1; result.Message = "已存在此用户"; } } catch (Exception ex) { //System.Reflection.MethodInfo.GetCurrentMethod().Name Logger.WriteException("VerifyAccount", ex, request); result.ErrCode = -1; result.Message = ex.Message; } return(result); }
public HttpResponseMessage Post(CustomerTransaction ct) { ClaimsPrincipal p = RequestContext.Principal as ClaimsPrincipal; CustomerDA.LowerBalance(ct.VerschilBedrag, ct.RijksregisterNummer, p.Claims); return(new HttpResponseMessage(HttpStatusCode.OK)); }
/// <summary> /// 新增用户 /// </summary> /// <param name="customer">用户的注册信息</param> /// <returns>用户信息</returns> public static CustomerInfo CreateCustomer(CustomerInfo customer) { try { CustomerInfo item = CustomerDA.CreateCustomer(customer); if (item.SysNo > 0) { if (!string.IsNullOrEmpty(customer.Email)) { AsyncEmail email = new AsyncEmail(); string mailSubject = string.Empty; email.MailAddress = customer.Email; email.CustomerID = item.CustomerID; email.ImgBaseUrl = ConstValue.CDNWebDomain; email.Status = (int)EmailStatus.NotSend; email.MailBody = MailHelper.GetMailTemplateBody("RegisterSuccess", out mailSubject); email.MailSubject = mailSubject.Replace("[CustomerID]", item.CustomerID); email.MailBody = email.MailBody.Replace("[CustomerID]", item.CustomerID).Replace("[ImgBaseUrl]", email.ImgBaseUrl) .Replace("[WebBaseUrl]", ConstValue.WebDomain).Replace("[CurrentDateTime]", DateTime.Now.ToString("yyyy-MM-dd")).Replace("[Year]", DateTime.Now.Year.ToString()); EmailDA.SendEmail(email); } } return(item); } catch (Exception ex) { ECommerce.Utility.Logger.WriteLog(string.Format("用户注册异常,异常信息:{0}!", ex.ToString()), "RegisteCustomer", "RegisteCustomerFailure"); return(customer); } }
public void GetCustomerxName() { var da = new CustomerDA(); var lista = da.getCustomerxName(""); Assert.IsTrue(lista.Count > 0); }
protected void btnLogin_Click(object sender, EventArgs e) { string FN = txtFName.Text; string LN = txtLName.Text; try { // make an empty customer object Customer cust = new Customer(); cust = CustomerDA.FindCustomer(FN, LN); if (cust == null) { lblLogErr.Text = "Either the entered info is not correct or such a user does not exist." + "If you are sure that you have already registered, please get sure that you enter correct info."; } else { lblLogErr.Text = @"You are successfully loged in! If you wish, you can go to the 'Lease Slip page' for a new lease."; Session.Add("customer", cust); hplLease.Visible = true; btnLogin.Visible = false; } } catch (Exception ex) { throw new Exception("Data error occurred. Contact application support.", ex); } }
public void Update() { var da = new CustomerDA(); var entity = new Customer { CustomerId = 62, FirstName = "Oscar2", LastName = "Taya2", Company = "Reprodata", Address = "Av. Simon 123", City = "Lima", State = "Lima", Country = "Perú", PostalCode = "1245", Phone = "4563214", Fax = "46512321", Email = "*****@*****.**", SupportRepId = null }; var result = da.Update(entity); Assert.IsTrue(result); }
public void GetCustomer() { var da = new CustomerDA(); var entity = da.Get(60); Assert.IsTrue(entity.CustomerId > 0); }
public void GetAllCustomer() { var da = new CustomerDA(); var lista = da.GetAll("Pedro Ruiz"); Assert.IsTrue(lista.Count > 0); }
/// <summary> /// 查询用户优惠券 /// </summary> /// <param name="query">查询信息</param> /// <returns></returns> public static QueryResult <CustomerCouponInfo> QueryCouponCode(CustomerCouponCodeQueryInfo query) { var memberInfo = CustomerDA.GetCustomerInfo(query.CustomerSysNo); query.CustomerRank = (int)memberInfo.CustomerRank; return(CustomerDA.QueryCouponCode(query)); }
// if shipping details are empty redirect the user to shipping=true public void EmptyShippingInfo() { // makes sure vales are not empty to avoid nullreference exception if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated || Session["AnonymousUserName"] != null) { //Instantiate our customer specific DataAccess Class CustomerDA customerDA = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer = new Customer(); //gets customer info based on customer id customer.Id = int.Parse(GetCustomerID()); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); // makes sure vales are not empty to avoid nullreference exception if (getCustomer[0].FirstName == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].LastName == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].Address == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].Address2 == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].City == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].State == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].Zip == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } if (getCustomer[0].Country == "") { Response.Redirect("CheckOut.aspx?Shipping=true"); } } }
/// <summary> /// 查询余额 /// </summary> /// <param name="filter"></param> /// <returns></returns> public static PointListView GetPointListView(PointQueryInfoFilter filter1, PointQueryInfoFilter filter2) { PointListView listView = new PointListView(); listView.PointObtainList = CustomerDA.GetPointObtainList(filter1); // (ConstructQueryInfo(customerID, "Obtain")); listView.PointConsumeList = CustomerDA.GetPointConsumeList(filter2); // (ConstructQueryInfo(customerID, "Consume")); return(listView); }
public static string ModifyOrderMemo(int soSysNo, string memo) { if (CustomerDA.UpdateOrderMemo(soSysNo, memo) > 0) { return("修改成功"); } return("修改失败"); }
public static List <OrderInfo> GetCenterOrderMasterList(int customerSysNo, List <string> sosysnos) { if (sosysnos.Count > 0) { return(CustomerDA.GetCenterOrderMasterList(customerSysNo, sosysnos)); } return(new List <OrderInfo>()); }
public DataSet GetCustomer(string customerid) { try { CustomerDA cda = new CustomerDA(); return cda.GetCustomer(customerid); } catch (Exception ex) { } return null; }
public string VerifyLoginInfo(String username, String password) { try { CustomerDA cda = new CustomerDA(); return cda.VerifyLoginInfo(username,password); } catch (Exception ex) { } return null; }
protected void btnAddToCart_Click(object sender, EventArgs e) { // try catch for notifying the user when they // try to enter an item to their shopping cart // that is already in their shopping cart try { // call method to get values from the labels and textboxes // on the formview GetItems(); // check to see if user is logged on if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { // get the customerID of the user who is logged on // get the id of the user that I just created Customer customer = new Customer(); customer.Username = User.Identity.Name; CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomersID = customerIDDA.Get(customer); customerID = getCustomersID[0].Id; // clear customer = null; customerIDDA = null; // count how many orders that have not been verified exist in the orders table Order order = new Order(); order.CustomerId = int.Parse(customerID.ToString()); order.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrders = orderDA.Get(order); // returns one item countOrders = getOrders.Count; //clear order = null; orderDA = null; getOrders = null; // if there are no orders with a txnID = "" then add a new order // then get the OrderID of the Order to add items to the shopping // cart using that OrderID // if there are orders with a txnID = "" then select the OrderID // and add orders to the shopping cart using that OrderID if (int.Parse(countOrders.ToString()) == 0) { // add a new order to the order table // instantiate class DAL.DataAccess da6 = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); // make command statement string comm6 = "INSERT INTO Orders VALUES (@customerID, @grossTotal, @tax, @netTotal, @txnID, @paymentStatus)"; // make arrays for paramaters and input string[] s6 = { "@customerID", "@grossTotal", "@tax", "@netTotal", "@txnID", "@paymentStatus" }; string[] v6 = { customerID.ToString(), "0", "0", "0", "", "" }; da6.ExecuteNonQuery(comm6, s6, v6); //clear s6 = null; v6 = null; // get the orderID of the order that was just created // insert sale price Order orderIID = new Order(); orderIID.CustomerId = int.Parse(customerID.ToString()); orderIID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrder = orderIDDA.Get(orderIID); orderID = getOrder[0].Id; //clear orderIID = null; getOrder = null; // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the OrderID that was created // instantiate class // insert sale price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; //// tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; Response.Redirect(Request.RawUrl); } else { // insert regular price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString("n2")); orderItem.TotalPrice = decimal.Parse(price.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); // Response.Redirect(Request.RawUrl); } } else { // get the orderID of the user that has a txnID = "" // instantiate class Order orderIID = new Order(); orderIID.CustomerId = int.Parse(customerID.ToString()); orderIID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrder = orderIDDA.Get(orderIID); orderID = getOrder[0].Id; //clear orderIID = null; getOrder = null; // check to see if the customer has the item in their cart already. // if they do, do not insert item into database OrderItem orderItemExistence = new OrderItem(); orderItemExistence.OrderId = int.Parse(orderID.ToString()); orderItemExistence.ItemId = itemID.Text; OrderItemDA orderItemExistenceDA = new OrderItemDA(); Collection<OrderItem> getOrderItemExistence = orderItemExistenceDA.Get(orderItemExistence); countItems = getOrderItemExistence.Count; if (countItems > 0) { error.Text = "This item is in your shopping cart."; error.Visible = true; } else { // see if item is on sale if (isItemOnSale() == true) { // insert sale price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert regular price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString("n2")); orderItem.TotalPrice = decimal.Parse(price.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } } } // if user is not logged on make up and account else { // if the anonymous session anonymouscustomerID is empty // create a new username and customerID if (Session["AnonymousUserName"] == null) { // get all rows to get maximum customerID CustomerDA customerDA = new CustomerDA(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomers = customerDA.Get(null); // gets max customerID in table // adds one and combines websites domain name // with the anonymousID max = (int)getCustomers[getCustomers.Count - 1].Id; usernameID = int.Parse(max.ToString()) + 1; anonymousUserName = "******" + usernameID; //clear customerDA = null; getCustomers = null; // insert the anonymousCustomerID into the customer table with the username of // and the usernameID/customerID // mypetsfw.com + customerID Customer customer = new Customer(usernameID, true, anonymousUserName, "Fill In", "Fill In", "Fill In", "Fill In", "Fill In", "", "Fill In", ""); CustomerDA customerDA1 = new CustomerDA(); customerDA1.Save(customer); // clear customer = null; customerDA = null; // put the anonymoususername in a session Session["AnonymousUserName"] = anonymousUserName.ToString(); // create a new order of the anonymous user // add a new order to the order table // instantiate class Order oID1 = new Order(); oID1.Id = GetOrderIDPlusOne(); oID1.CustomerId = usernameID; oID1.GrossTotal = 0; oID1.Tax = 0; oID1.NetTotal = 0; // for payment status oID1.TxnId = ""; OrderDA orderIDDA1 = new OrderDA(); // save orderIDDA1.Save(oID1); //DAL.DataAccess da11 = // new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //// make command statement //string comm11 = "INSERT INTO Orders VALUES (@customerID, @grossTotal, @tax, @netTotal, @txnID, @paymentStatus)"; //// make arrays for paramaters and input //string[] s11 = { "@customerID", "@grossTotal", "@tax", "@netTotal", "@txnID", "@paymentStatus" }; //string[] v11 = { usernameID.ToString(), "0", "0", "0", "", "" }; //da11.ExecuteNonQuery(comm11, s11, v11); //clear oID1 = null; orderIDDA1 = null; // get the orderID of the anonymoususer // get the id of the user that I just created Order oID = new Order(); oID.CustomerId = usernameID; oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderID = getOrderID[0].Id; //clear oID = null; getOrderID = null; // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell anonymous the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString()); orderItem.TotalPrice = decimal.Parse(price.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell anonymous the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } // if the session doesn't != null else { // get the customerID of the user that I just created Customer customer2 = new Customer(); customer2.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerDA2 = new CustomerDA(); Collection<Customer> getCustomers2 = customerDA2.Get(customer2); customerID = getCustomers2[0].Id; // clear customer2 = null; customerDA2 = null; getCustomers2 = null; // see if an order doesn't already exist for the anonymousUser // count how many orderIDs that have not been verified exist in the orders table Order orders = new Order(); orders.CustomerId = int.Parse(customerID.ToString()); orders.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrder = orderDA.Get(orders); // returns one item countOrders = getOrder.Count; //clear orders = null; orderDA = null; getOrder = null; // if there are no orders with a txnID = "" then add a new order // then get the OrderID of the Order to add items to the shopping // cart using that OrderID // if there are orders with a txnID = "" then select the OrderID // and add orders to the shopping cart using that OrderID if (int.Parse(countOrders.ToString()) == 0) { // get the customerID of the user that I just created Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomers3 = customerIDDA.Get(customerIDID); customerID = getCustomers3[0].Id; // clear customerIDID = null; customerIDDA = null; getCustomers3 = null; // create a new order of the anonymous user // add a new order to the order table // instantiate class Order oID1 = new Order(); oID1.Id = GetOrderIDPlusOne(); oID1.CustomerId = usernameID; oID1.GrossTotal = 0; oID1.Tax = 0; oID1.NetTotal = 0; // for payment status oID1.TxnId = ""; OrderDA orderIDDA1 = new OrderDA(); // save orderIDDA1.Save(oID1); //DAL.DataAccess da11 = // new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //// make command statement //string comm11 = "INSERT INTO Orders VALUES (@customerID, @grossTotal, @tax, @netTotal, @txnID, @paymentStatus)"; //// make arrays for paramaters and input //string[] s11 = { "@customerID", "@grossTotal", "@tax", "@netTotal", "@txnID", "@paymentStatus" }; //string[] v11 = { customerID.ToString(), "0", "0", "0", "", "" }; //da11.ExecuteNonQuery(comm11, s11, v11); //clear oID1 = null; orderIDDA1 = null; // get the orderid for the anonymous users new order Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderID = int.Parse(getOrderID[0].Id.ToString()); //clear oID = null; orderIDDA = null; getOrderID = null; // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString()); orderItem.TotalPrice = decimal.Parse(price.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } // if an order is open and exists for the anonymous user else { // get the customerID of the user that I just created Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomers3 = customerIDDA.Get(customerIDID); customerID = getCustomers3[0].Id; // clear customerIDID = null; customerIDDA = null; getCustomers3 = null; // get the orderID of the anonymoususer that has a txnID = "" // instantiate class Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderID = getOrderID[0].Id; //clear oID = null; orderIDDA = null; getOrderID = null; // check to see if the anonymous user has the item in their cart already. // if they do, do not insert item into database OrderItem orderItemExistence = new OrderItem(); orderItemExistence.OrderId = int.Parse(orderID.ToString()); orderItemExistence.ItemId = itemID.Text; OrderItemDA orderItemExistenceDA = new OrderItemDA(); Collection<OrderItem> getOrderItemExistence = orderItemExistenceDA.Get(orderItemExistence); countItems = getOrderItemExistence.Count; if (countItems > 0) { error.Text = "This item is in your shopping cart."; error.Visible = true; } else { // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the existing OrdersID // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert item into the database using the existing OrdersID // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString()); orderItem.TotalPrice = decimal.Parse(price.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } } } } } catch (SqlException) { // error.Text = "The item is in your shopping cart already."; // error.Visible = true; } catch (Exception) { } }
// on logged in protected void LoggedIn(object sender, EventArgs e) { // seeing if there is an order just in case I missed something if (Session["AnonymousUserName"] != null) { // if the user has an order on going delete it and replace it // with the items that the anonymous user just made(which is really a customer) //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer = new Customer(); //gets customer info based on customer username customer.Username = UserLogin.UserName; //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); // count orders with customerid = @customerid and txtnid = @txnid // instantiate class Order orders = new Order(); orders.CustomerId = getCustomer[0].Id; orders.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrders = orderDA.Get(orders); // returns number of orders object getOrder = getOrders.Count; //clear orders = null; orderDA = null; getOrders = null; // if the user who is logged has items in his cart as an anonymous user // delete the items he had previously on his cart and add the new items and order // that they just put into his cart if (int.Parse(getOrder.ToString()) > 0) { // get the orderID of the customer that he had on going order // instantiate class Order oID = new Order(); oID.CustomerId = getCustomer[0].Id; oID.TxnId = ""; OrderDA ordersDA = new OrderDA(); Collection<Order> getOID = ordersDA.Get(oID); // returns one item object getOrderID = getOID[0].Id; //clear oID = null; ordersDA = null; getOID = null; // delete the order and items that involve the order above // delete items from the orderItem table associated with that order if any //Create an Object that specifies what we want to Get // OrderItem deleteOrderItem = new OrderItem(); //OrderItemDA deleteOrderItemDA = new OrderItemDA(); ////gets orderItem info based on customerID //deleteOrderItem.OrderId = int.Parse(getOrderID.ToString()); //// deletes the orderItems with that customerID //deleteOrderItemDA.Delete(deleteOrderItem); //// clear //deleteOrderItemDA = null; //deleteOrderItem = null; DAL.DataAccess da5 = new DAL.DataAccess( ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); string comm5 = "Delete FROM OrderItem WHERE OrderID = @orderID"; // array with orderID string[] p5 = { "@orderID" }; string[] v5 = { getOrderID.ToString() }; da5.ExecuteNonQuery(comm5, p5, v5); // clear p5 = null; v5 = null; // delete order //Instantiate our Order specific DataAccess Class OrderDA deleteOrderDA = new OrderDA(); //Create an Object that specifies what we want to Get Order deleteOrder = new Order(); //gets order info based on customerID deleteOrder.Id = int.Parse(getOrderID.ToString()); // deletes the order with that customerID deleteOrderDA.Delete(deleteOrder); // clear deleteOrderDA = null; deleteOrder = null; // get cusotmerID of anonymous user //Instantiate our Category specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer2 = new Customer(); //gets customer info based on customer username customer2.Username = Session["AnonymousUserName"].ToString(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer2 = customerDA2.Get(customer2); //for (int i = 0; i < getCustomer2.Count; i++) //{ // getCustomer2[i].Id; //} // get orderID of anonymous user //Create an Object that specifies what we want to Get Order ordersID = new Order(); //gets order info based on customerID ordersID.CustomerId = getCustomer2[0].Id; OrderDA ordersIDDA = new OrderDA(); // deletes the order with that customerID Collection<Order> getOrder2 = ordersIDDA.Get(ordersID); // update the customerid of the anonymous order to the customer, of the user who just logged on DAL.DataAccess da4 = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); string comm4 = "UPDATE Orders SET CustomerID = @customerID WHERE OrderID = @orderID AND TXNID = @txnID"; // empty array string[] p4 = { "@customerID", "@orderID", "@txnID" }; string[] v4 = { getCustomer[0].Id.ToString(), getOrder2[0].Id.ToString(), "" }; // new cus old get order da4.ExecuteNonQuery(comm4, p4, v4); // clear p4 = null; v4 = null; // delete anonymous customer from customer table Customer customers = new Customer(); customers.Id = getCustomer2[0].Id; CustomerDA customersDA = new CustomerDA(); customersDA.Delete(customers); // clear customers = null; customersDA = null; //abandon session Session.Abandon(); Session.Clear(); } // if user doesn't have an on going order just // change the customer ID on the order else { // get cusotmerID of anonymous user //Instantiate our Category specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer2 = new Customer(); //gets customer info based on customer username customer2.Username = Session["AnonymousUserName"].ToString(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer2 = customerDA2.Get(customer2); //for (int i = 0; i < getCustomer2.Count; i++) //{ // getCustomer2[i].Id; //} // get orderID of anonymous user based on customerID OrderDA ordersIDDA = new OrderDA(); //Create an Object that specifies what we want to Get Order ordersID = new Order(); //gets order info based on customerID ordersID.CustomerId = getCustomer2[0].Id; // deletes the order with that customerID Collection<Order> getOrder2 = ordersIDDA.Get(ordersID); // update the customerid of the anonymous order to the customer, of the user who just logged on DAL.DataAccess da4 = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); string comm4 = "UPDATE Orders SET CustomerID = @customerID WHERE OrderID = @orderID AND TXNID = @txnID"; // empty array string[] p4 = { "@customerID", "@orderID", "@txnID" }; string[] v4 = { getCustomer[0].Id.ToString(), getOrder2[0].Id.ToString(), "" }; // new cus old get order da4.ExecuteNonQuery(comm4, p4, v4); // clear p4 = null; v4 = null; // delete anonymous customer from customer table Customer customers = new Customer(); customers.Id = getCustomer2[0].Id; CustomerDA customersDA = new CustomerDA(); customersDA.Delete(customers); // clear customers = null; customersDA = null; //DAL.DataAccess da8 = // new DAL.DataAccess( // ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //string comm8 = // "Delete FROM Customer WHERE CustomerID = @customerID"; //// array with customerID //string[] p8 = { "@customerID" }; //string[] v8 = { getCustomer2[0].Id.ToString() }; //da8.ExecuteNonQuery(comm8, p8, v8); //// clear //p8 = null; //v8 = null; //abandon session Session.Abandon(); Session.Clear(); } } }
protected void Page_Load(object sender, EventArgs e) { lblItemsInCart.Text = "0"; if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { // get the customerID of the user who is logged on // update customer information Customer customerIDID = new Customer(); customerIDID.Username = Membership.GetUser().UserName; //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); Collection<Customer> getCustomerID = customerDA.Get(customerIDID); // returns one item // customerID = ds5.Tables[0].Rows[0].ItemArray[0]; // if statement added by Ethan, will set customerID = 0 if no rows returned. if (getCustomerID.Count > 0) { customerID = getCustomerID[0].Id; ; } else { customerID = 0; } //clear customerIDID = null; customerDA = null; getCustomerID = null; // count how many orders exists from the user that is logged on Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderCount = getOrderID.Count; // clear oID = null; orderIDDA = null; getOrderID = null; if (int.Parse(orderCount.ToString()) == 0) { // display answer on label lblItemsInCart.Text = "0"; } else { // get the orderID of the order that has a txnid = "" of the customer Order orderIDID = new Order(); orderIDID.CustomerId = int.Parse(customerID.ToString()); orderIDID.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrderIDID = orderDA.Get(orderIDID); orderID = getOrderIDID[0].Id; // clear oID = null; orderIDDA = null; getOrderID = null; //count how many items are in the shopping cart for the user //and display them //instantiate class OrderItem orderItemCount = new OrderItem(); orderItemCount.OrderId = int.Parse(orderID.ToString()); OrderItemDA orderItemCountDA = new OrderItemDA(); Collection<OrderItem> getOrderItemCount = orderItemCountDA.Get(orderItemCount); items = getOrderItemCount.Count; // clear orderItemCount = null; orderItemCountDA = null; getOrderItemCount = null; // display answer on label lblItemsInCart.Text = items.ToString(); } } else { // if the customer is not logged on but has an item in there cart if (Session["AnonymousUserName"] != null) { // get the customerID Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); Collection<Customer> getCustomerID = customerDA.Get(customerIDID); customerID = getCustomerID[0].Id.ToString(); //clear customerIDID = null; customerDA = null; getCustomerID = null; // get the current orderID if any if not make shopping cart items 0 // count how many orders exists from the user that is logged on Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderCount = getOrderID.Count; // clear oID = null; orderIDDA = null; getOrderID = null; if (int.Parse(orderCount.ToString()) == 0) { // display answer on label lblItemsInCart.Text = "0"; } else { // get the customerID // get the customerID Customer customerIDID2 = new Customer(); customerIDID2.Username = Session["AnonymousUserName"].ToString(); //Instantiate our Category specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); Collection<Customer> getCustomerID2 = customerDA2.Get(customerIDID2); customerID = getCustomerID2[0].Id; //clear customerIDID2 = null; customerDA2 = null; getCustomerID2 = null; // get the orderID of the order with the txnid = "" for the anonyomous user Order oID2 = new Order(); oID2.CustomerId = int.Parse(customerID.ToString()); oID2.TxnId = ""; OrderDA orderIDDA2 = new OrderDA(); Collection<Order> getOrderID2 = orderIDDA2.Get(oID2); orderID = getOrderID2[0].Id; // clear oID2 = null; orderIDDA2 = null; getOrderID2 = null; //count how many items are in the shopping cart for the anonymous user //and display them //instantiate class OrderItem orderItemCount = new OrderItem(); orderItemCount.OrderId = int.Parse(orderID.ToString()); OrderItemDA orderItemCountDA = new OrderItemDA(); Collection<OrderItem> getOrderItemCount = orderItemCountDA.Get(orderItemCount); items = getOrderItemCount.Count; // clear orderItemCount = null; orderItemCountDA = null; getOrderItemCount = null; // display answer on label lblItemsInCart.Text = items.ToString(); } } } }
/// <summary> /// This method sets up addition user registration information. This code runs after /// the user has been registered to the ASP.Net tables. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void userRegistrationWizard_CreatedUser(object sender, EventArgs e) { // get references to the textboxes on the page MembershipUser newUser = Membership.GetUser(userRegistrationWizard.UserName); var txtFirstName = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("txtFirstName"); var txtLastName = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("txtLastName"); var txtAddress = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress"); var txtAddress2 = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress2"); var txtCity = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("txtCity"); var cboState = (DropDownList)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("cboState"); var txtZip = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("txtZip"); var cboCountry = (DropDownList)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("cboCountry"); // create a customer dataaccess object CustomerDA customerDA = new CustomerDA(); try { // get a collection of the current list of rows in the DB Collection<Customer> customerCollection = customerDA.Get(null); // get the last user ID in the table int? newUserID = customerCollection[customerCollection.Count - 1].Id + 1; // create a customer business object Customer customerObj = new Customer(newUserID, true, newUser.UserName, txtFirstName.Text, txtLastName.Text, txtAddress.Text, txtAddress2.Text, txtCity.Text, cboState.Text, txtZip.Text, cboCountry.Text); // commit customer business object to the DB using the CustomerDA customerDA.Save(customerObj); }catch(Exception ex) { // there was an error creating the users account, delete the users account Membership.DeleteUser(newUser.UserName); } if (Session["AnonymousUserName"] != null) { // get customerid of user to use customer id // for updating user information //Instantiate our customer specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); //Create an Object that specifies what we want to Get Customer customer2 = new Customer(); //gets customer info based on customer username customer2.Username = Session["AnonymousUserName"].ToString(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer2 = customerDA.Get(customer2); TextBox userName = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); TextBox firstName = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtFirstName"); TextBox lastName = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtLastName"); TextBox address = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtAddress"); TextBox address2 = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtAddress2"); TextBox city = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtCity"); DropDownList state = (DropDownList) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("cboState"); TextBox zipCode = (TextBox) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtZip"); DropDownList country = (DropDownList) userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("cboCountry"); // update customer information Customer customerShipping = new Customer(); customerShipping.Id = getCustomer2[0].Id; customerShipping.IsActive = true; customerShipping.Username = userName.Text; customerShipping.FirstName = firstName.Text; customerShipping.LastName = lastName.Text; customerShipping.Address = address.Text; customerShipping.Address2 = address2.Text; customerShipping.City = city.Text; customerShipping.State = state.Text; customerShipping.Zip = zipCode.Text; customerShipping.Country = country.Text; //Instantiate our customer specific DataAccess Class CustomerDA customerDAShipping = new CustomerDA(); // save customer information customerDAShipping.Save(customerShipping); // clear customerShipping = null; customerDAShipping = null; // LogIn User System.Web.Security.FormsAuthentication.SetAuthCookie(userName.Text, false); //abandon session Session.Abandon(); Session.Clear(); } }
public string InsertCustomer(string appid) { try { CustomerDA cda = new CustomerDA(); return cda.InsertCustomer(appid); } catch (Exception ex) { } return ""; }
/// <summary> /// Checks user input for errors, then commits changes to customer info /// in the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmitChanges_Click(object sender, EventArgs e) { // used for zip TryParse int result = 0; // check values of the textboxes, displaying the appropriate values, then // commit changes to the DB if (txtFirstName.Text == "" || txtFirstName.Text == "First Name") { ErrorText.Text = "First name required"; } else if (txtLastName.Text == "" || txtLastName.Text == "Last Name") { ErrorText.Text = "Last name required"; } else if (txtAddress.Text == "" || txtAddress.Text == "Address 1") { ErrorText.Text = "Address 1 required"; } else if (txtCity.Text == "" || txtCity.Text == "City") { ErrorText.Text = "City name required"; } else if (!int.TryParse(txtZip.Text, out result)) { ErrorText.Text = "Invalid Zip"; } else if (txtEmail.Text == "" || txtEmail.Text == "E-Mail") { ErrorText.Text = "E-Mail required"; } else { // create customer data access object CustomerDA customerDA = new CustomerDA(); // get references to the textboxes on the page MembershipUser currentUser = Membership.GetUser(); try { // create a customer business object Customer customerObj = new Customer(customerID, true, currentUser.UserName, txtFirstName.Text, txtLastName.Text, txtAddress.Text, txtAddress2.Text, txtCity.Text, cboState.Text, txtZip.Text, cboCountry.Text); // commit customer business object to the DB using the CustomerDA customerDA.Save(customerObj); // Update user e-mail currentUser.Email = txtEmail.Text; Membership.UpdateUser(currentUser); } catch (Exception ex) { // there was an error in updating the users account Response.Redirect("~/404.aspx"); } // redirect the user back to their profile Response.Redirect("ViewProfile.aspx"); } }
protected void Page_LoadComplete(object sender, EventArgs e) { if (Membership.GetUser() != null && !Page.IsPostBack) { // create customer object to search for Customer customerSearchObject = new Customer(null, null, Membership.GetUser().UserName, null, null, null, null, null, null, null, null); // get current user customer account information from the database CustomerDA customerDA = new CustomerDA(); Collection<Customer> customerInfo = customerDA.GetLike(customerSearchObject); // place customer ID into a variable for updating the customer customerID = (int)customerInfo[0].Id; // put the user information into the form txtFirstName.Text = customerInfo[0].FirstName; txtLastName.Text = customerInfo[0].LastName; txtAddress.Text = customerInfo[0].Address; if (customerInfo[0].Address2 != null) txtAddress2.Text = customerInfo[0].Address2; txtCity.Text = customerInfo[0].City; cboState.Text = customerInfo[0].State; txtZip.Text = customerInfo[0].Zip; cboCountry.Text = customerInfo[0].Country; txtEmail.Text = Membership.GetUser().Email; } else { // user not logged in, redirect user to login page if (!Page.IsPostBack) Response.Redirect("Login.aspx"); } }
// on user created // get the customerid of the user who is making an account // register user using the customerID // redirect user to shipping protected void ReconfigureOrder(object sender, EventArgs e) { if (Session["AnonymousUserName"] != null) { // get customerid of user to use customer id // for updating user information //Instantiate our customer specific DataAccess Class CustomerDA customerDA = new CustomerDA(); //Create an Object that specifies what we want to Get Customer customer = new Customer(); //gets customer info based on customer username customer.Username = Session["AnonymousUserName"].ToString(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); TextBox userName = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); TextBox firstName = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtFirstName"); TextBox lastName = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtLastName"); TextBox address = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtAddress"); TextBox address2 = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtAddress2"); TextBox city = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtCity"); DropDownList state = (DropDownList)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("cboState"); TextBox zipCode = (TextBox)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("RtxtZip"); DropDownList country = (DropDownList)userRegistrationWizard.CreateUserStep.ContentTemplateContainer.FindControl("cboCountry"); // update customer information Customer customerShipping = new Customer(); customerShipping.Id = getCustomer[0].Id; customerShipping.IsActive = true; customerShipping.Username = userName.Text; customerShipping.FirstName = firstName.Text; customerShipping.LastName = lastName.Text; customerShipping.Address = address.Text; customerShipping.Address2 = address2.Text; customerShipping.City = city.Text; customerShipping.State = state.Text; customerShipping.Zip = zipCode.Text; customerShipping.Country = country.Text; //Instantiate our customer specific DataAccess Class CustomerDA customerDAShipping = new CustomerDA(); // save customer information customerDAShipping.Save(customerShipping); // clear customerShipping = null; customerDAShipping = null; // LogIn User System.Web.Security.FormsAuthentication.SetAuthCookie(userName.Text, false); //abandon session Session.Abandon(); Session.Clear(); // redirect user to shipping=true Response.Redirect("CheckOut.aspx?Shipping=true"); } }
// method for binding RPTShipping private void BindRPTShipping() { //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer = new Customer(); //gets customer info based on customer id customer.Id = int.Parse(GetCustomerID()); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); rptShippingAddress.DataSource = getCustomer; rptShippingAddress.DataBind(); }
// gets state of user that is logged in or has a session to calculate the tax public string GetState() { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated || Session["AnonymousUserName"] != null) { //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer = new Customer(); //gets customer info based on customer id customer.Id = int.Parse(GetCustomerID()); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); return getCustomer[0].State; } return ""; }
protected void GetShippingInformation() { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated || Session["AnonymousUserName"] != null) { //gets customer info based on customer id Customer customer = new Customer(); customer.Id = int.Parse(GetCustomerID()); CustomerDA customerDA = new CustomerDA(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); // makes sure vales are not empty to avoid nullreference exception if (getCustomer[0].FirstName != "") { txtFirstName.Text = getCustomer[0].FirstName; } if (getCustomer[0].LastName != "") { txtLastName.Text = getCustomer[0].LastName; } if (getCustomer[0].Address != "") { txtAddress1.Text = getCustomer[0].Address; } if (getCustomer[0].Address2 != "") { txtAddress2.Text = getCustomer[0].Address2; } if (getCustomer[0].City != "") { txtCity.Text = getCustomer[0].City; } if (getCustomer[0].State != "") { ddlState.Text = getCustomer[0].State; } if (getCustomer[0].Zip != "") { txtZipCode.Text = getCustomer[0].Zip; } if (getCustomer[0].Country != "") { ddlCountry.Text = getCustomer[0].Country; } } }
// retrieves customerID of anonymous and customer public string GetCustomerID() { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { // get the customerID of the user who is logged on Customer customerIDID = new Customer(); customerIDID.Username = User.Identity.Name; CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomers3 = customerIDDA.Get(customerIDID); customerID = getCustomers3[0].Id; // clear customerIDID = null; customerIDDA = null; getCustomers3 = null; return customerID.ToString(); } else { // get the customerID of the user who is logged on // get the customerID of the user who is logged on Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomers3 = customerIDDA.Get(customerIDID); customerID = getCustomers3[0].Id; // clear customerIDID = null; customerIDDA = null; getCustomers3 = null; return customerID.ToString(); } }
protected void btnSubmitDetails_Click(object sender, EventArgs e) { // update info for anonymous users of orders table for the customer / anonymous user Customer customers = new Customer(); customers.Id = int.Parse(GetCustomerID()); customers.FirstName = txtFirstName.Text; customers.LastName = txtLastName.Text; customers.Address = txtAddress1.Text; customers.Address2 = txtAddress2.Text; customers.City = txtCity.Text; customers.State = ddlState.SelectedItem.Text; customers.Zip = txtZipCode.Text; customers.Country = ddlCountry.SelectedItem.Text; CustomerDA customersDA = new CustomerDA(); customersDA.Save(customers); //DAL.DataAccess da1 = // new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //string comm1 = // "UPDATE Customer SET FName = @fName, LName = @lName, Address = @address, Address2 = @address2, City = @city, State = @state, Zip = @zip, Country = @country WHERE CustomerID = @customerID"; //// empty array //string[] p1 = { "@fName", "@lName", "@address", "@address2", "@city", "@state", "@zip", "@country", "@customerID" }; //string[] v1 = { txtFirstName.Text, txtLastName.Text, txtAddress1.Text, txtAddress2.Text, txtCity.Text, ddlState.SelectedItem.Text, txtZipCode.Text, ddlCountry.SelectedItem.Text, GetCustomerID() }; //da1.ExecuteNonQuery(comm1, p1, v1); // clear customers = null; customersDA = null; // redirect the user Response.Redirect("~/CheckOut.aspx?OrderReview=true"); }