public string PostMyPage(Customer_Information MyInfo) { if (MyInfo != null) { try { Customer_Information a = Data.Customer_Information.Single(x => x.Customer_id == MyInfo.Customer_id); a.Name = MyInfo.Name; a.Address = MyInfo.Address; a.Phone = MyInfo.Phone; a.Email = MyInfo.Email; a.Type = MyInfo.Type; a.User_id = MyInfo.User_id; a.Password = MyInfo.Password; Data.Entry(a).State = EntityState.Modified; return("Informations are Updated Successfully."); } catch { return("Informations are Not Updated. Please Try Later"); } } else { return("Informations are Not Updated. Please Try Later"); } }
public string Register(MyUserAccount account) { try { Customer_Information a = new Customer_Information(); a.Name = account.Name; a.Address = account.Address; a.Phone = int.Parse(account.Phone); a.Email = account.Email; a.Type = account.Type; a.User_id = account.UserName; a.Password = account.Password; Data.Customer_Information.Add(a); Data.SaveChanges(); return(account.Name + " " + " is Successfully Registered"); } catch { return(account.Name + " " + " is Not Registered. Try Again "); } }
private void btnLogin_Click(object sender, EventArgs e) { try { objCus = db.Customer_Informations.SingleOrDefault(p => p.username == txtUser.Text.Trim()); objClient = db.clients.SingleOrDefault(p => p.clientName.Contains(Environment.MachineName)); if (objClient == null) { MessageBox.Show("Vui lòng tạo tên máy trong hệ thống trước khi login.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (objCus != null) { db.Refresh(RefreshMode.KeepChanges, objCus); if (objCus.currentMoney.GetValueOrDefault() > 0) { if (db.Login_Customers.Where(p => p.idCus == objCus.idCus).Count() > 0) { MessageBox.Show("Tài khoản của bạn đang được login tại một máy khác.Vui lòng kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var objLogin_Cus = new Login_Customer(); objLogin_Cus.idClient = objClient.idClient; objLogin_Cus.idCus = objCus.idCus; objLogin_Cus.startTime = DateTime.Now; db.Login_Customers.InsertOnSubmit(objLogin_Cus); db.SubmitChanges(); Properties.Settings.Default.idCus = objCus.idCus; Properties.Settings.Default.idLoginCus = objLogin_Cus.ID; Properties.Settings.Default.idClient = objClient.idClient; Properties.Settings.Default.Save(); this.Hide(); using (var frm = new frmMain()) { frm.ShowDialog(); } } else { MessageBox.Show("Tài khoản của bạn hiện không đủ để đăng nhập.Vui lòng nạp thêm tiền!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtUser.Text = ""; txtPass.Text = ""; txtUser.Focus(); } } else { txtUser.Text = ""; txtPass.Text = ""; txtUser.Focus(); } } catch (Exception ex) { MessageBox.Show("Lỗi:" + ex.Message, "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Customer_Information GetDelete(int?id) { try { Customer_Information customer_Information = Data.Customer_Information.Find(id); return(customer_Information); } catch { throw; } }
private void frmMain_Load(object sender, EventArgs e) { try { if (Properties.Settings.Default.idCus > 0) { objClient = db.clients.SingleOrDefault(p => p.clientName.Contains(Environment.MachineName)); objCus = db.Customer_Informations.FirstOrDefault(p => p.idCus == Properties.Settings.Default.idCus); this.Text = objCus.name.ToUpper(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public string PostDelete(int?id) { try { Customer_Information customer_Information = Data.Customer_Information.Find(id); Data.Customer_Information.Remove(customer_Information); Data.SaveChanges(); return("Index"); } catch { throw; } }
public ActionResult MyPage(Customer_Information information) { if (ModelState.IsValid) { TempData["Message"] = Info.PostMyPage(information); } else { TempData["Message"] = "Wrong Input"; } return(View()); }
public Customer_Information GetMyPage(int CustomerId) { Customer_Information c = Data.Customer_Information.Single(x => x.Customer_id == CustomerId); return(c); }
public string Submit(string Customer_id, string UserName) { try { List <Customer_Order> submitionList = Data.Customer_Order.Where(x => x.Purches_id == Customer_id && x.Order_Status == 1).ToList(); int Total = 0; System.Random rand = new System.Random((int)System.DateTime.Now.Ticks); int random = rand.Next(1, 100000000); string Path = @"D:\Repositories\HatBazar\Email_Document\Customer_Order\" + random + ".txt"; //Pass the filepath and filename to the StreamWriter Constructor //StreamWriter sw = new StreamWriter(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Document.txt"); StreamWriter sw = new StreamWriter(Path); //Write a line of text sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Customer_Order\Order1.txt")); sw.WriteLine("Date :" + DateTime.Now); //*************************************************** foreach (var i in submitionList) { if (i.Unit_name == "PACKAGE") { int packageid = (i.Product_id).Value; List <Package_With_Product> Item = Data.Package_With_Product.Where(x => x.Package_Id == packageid).ToList(); foreach (var product in Item) { Product_Stock CO = Data.Product_Stock.Single(Z => Z.Product_id == product.Product_Id); int J = Int32.Parse(CO.Stock_unit); J = J - product.Unit_Number; CO.Stock_unit = J.ToString(); Data.Entry(CO).State = EntityState.Modified; bool Check = Data.Order_For_Shop.Any(x => x.Product_Name == (product.Product_Name)); if (Check == true) { Order_For_Shop order = Data.Order_For_Shop.Single(Z => Z.Product_Name == product.Product_Name); order.Unit_Number = product.Unit_Number + (order.Unit_Number); var price = Data.Product_Information.Single(x => x.Product_id == order.Product_Id); order.Total_Price = (order.Unit_Number) * (price.Price_per_unit); Data.Entry(order).State = EntityState.Modified; Product_SellingDate psd = new Product_SellingDate(); psd.Product_Id = order.Product_Id; psd.Product_Name = order.Product_Name; psd.Unit_Number = product.Unit_Number; psd.Unit_Name = order.Unit_Name; psd.Price = i.Price * product.Unit_Number; psd.Selected = 0; var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00 psd.Date = dateTimeNow.ToShortDateString(); Data.Product_SellingDate.Add(psd); Data.SaveChanges(); } else { Order_For_Shop OF = new Order_For_Shop(); OF.Product_Name = product.Product_Name; OF.Unit_Name = product.Unit_Name; OF.Unit_Number = product.Unit_Number; var price = Data.Product_Information.Single(x => x.Product_id == OF.Product_Id); OF.Total_Price = price.Price_per_unit; Data.Order_For_Shop.Add(OF); Product_SellingDate psd = new Product_SellingDate(); psd.Product_Id = OF.Product_Id; psd.Product_Name = product.Product_Name; psd.Unit_Number = product.Unit_Number; psd.Unit_Name = product.Unit_Name; psd.Price = i.Price * product.Unit_Number; psd.Selected = 0; var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00 psd.Date = dateTimeNow.ToShortDateString(); Data.Product_SellingDate.Add(psd); Data.SaveChanges(); } } } else { Product_Stock CO = Data.Product_Stock.Single(Z => Z.Product_id == (i.Product_id).Value); int J = Int32.Parse(CO.Stock_unit); J = J - (i.Unit_number).Value; CO.Stock_unit = J.ToString(); Data.Entry(CO).State = EntityState.Modified; bool Check = Data.Order_For_Shop.Any(x => x.Product_Name == (i.Product_Name)); if (Check == true) { Order_For_Shop order = Data.Order_For_Shop.Single(Z => Z.Product_Name == i.Product_Name); order.Unit_Number = (i.Unit_number).Value + (order.Unit_Number); var price = Data.Product_Information.Single(x => x.Product_name == order.Product_Name); // var price = Data.Product_Information.Single(x => x.Product_id == order.Product_Id); order.Total_Price = (order.Unit_Number) * (price.Price_per_unit); Data.Entry(order).State = EntityState.Modified; Product_SellingDate psd = new Product_SellingDate(); psd.Product_Id = order.Product_Id; psd.Product_Id = order.Product_Id; psd.Product_Name = order.Product_Name; psd.Unit_Number = i.Unit_number; psd.Unit_Name = order.Unit_Name; psd.Price = price.Price_per_unit * i.Unit_number; psd.Selected = 0; var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00 psd.Date = dateTimeNow.ToShortDateString(); Data.Product_SellingDate.Add(psd); Data.SaveChanges(); } else { Order_For_Shop OF = new Order_For_Shop(); //OF.Product_Id = (i.Product_id).Value; OF.Product_Name = i.Product_Name; OF.Unit_Name = i.Unit_name; OF.Unit_Number = (i.Unit_number).Value; Data.Order_For_Shop.Add(OF); Product_SellingDate psd = new Product_SellingDate(); psd.Product_Id = (i.Product_id).Value; psd.Product_Name = i.Product_Name; psd.Unit_Number = i.Unit_number; psd.Unit_Name = i.Unit_name; psd.Price = i.Price * i.Unit_number; psd.Selected = 0; var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00 psd.Date = dateTimeNow.ToShortDateString(); Data.Product_SellingDate.Add(psd); Data.SaveChanges(); } } i.Order_Status = 0; var date = DateTime.Now; i.Date = date.ToShortDateString(); Data.Entry(i).State = EntityState.Modified; //*********************************** try { string Information = "Product Name :" + i.Product_Name + "Unit :" + i.Unit_number + "" + i.Unit_name + "Price:" + (i.Unit_number * i.Price); sw.WriteLine(Information); Total = Total + (i.Unit_number * i.Price).Value; } catch { return("Path Missing to save Email."); } //*********************************** } Order_with_Date OD = new Order_with_Date(); var date2 = DateTime.Now; OD.Date = date2.ToShortDateString(); OD.User_Name = UserName; OD.Total_Price = Total; Data.Order_with_Date.Add(OD); Data.SaveChanges(); sw.WriteLine("Total : " + Total); sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Customer_Order\Order2.txt")); sw.Close(); IEmail_Service email = new Email_ServiceClass(); int ia = Int32.Parse(Customer_id); Customer_Information Info = Data.Customer_Information.Single(x => x.Customer_id == ia); Email_Service_Model obj = new Email_Service_Model(); obj.ToEmail = Info.Email; obj.EmailSubject = "Hat Bazar"; obj.EMailBody = System.IO.File.ReadAllText(Path); return(email.SendEmail(obj)); } catch { return("Submission Failure"); } }
public string Complain(Complain complain) { Customer_Complain CC = new Customer_Complain(); try { Customer_Information C = Data.Customer_Information.First(x => x.User_id == complain.User_Name); CC.Customer_ID = C.Customer_id; CC.DateTime = DateTime.Now; CC.Massage = complain.Message; Data.Customer_Complain.Add(CC); Data.SaveChanges(); //ModelState.Clear(); //TempData["Message"] = "Complain Submitted."; try { System.Random rand = new System.Random((int)System.DateTime.Now.Ticks); int random = rand.Next(1, 100000000); string Path = @"D:\Repositories\HatBazar\Email_Document\Admin_Email\" + random + ".txt"; //Pass the filepath and filename to the StreamWriter Constructor //StreamWriter sw = new StreamWriter(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Document.txt"); StreamWriter sw = new StreamWriter(Path); //Write a line of text sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Admin1.txt")); sw.WriteLine(complain.Message); sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Admin2.txt")); //Write a second line of text //sw.WriteLine("From the StreamWriter class"); //Close the file sw.Close(); try { //Email_ServiceController Email = new Email_ServiceController(); IEmail_Service Email = new Email_ServiceClass(); Email_Service_Model obj = new Email_Service_Model(); obj.ToEmail = C.Email; obj.EmailSubject = "Hat Bazar"; obj.EMailBody = System.IO.File.ReadAllText(Path); return(Email.SendEmail(obj)); } catch (Exception) { return("Problem while sending email, Please check details."); } } catch { return("Path Missing to save Email."); } } catch { //ModelState.Clear(); return("Invalid User Name."); } }