public ActionResult Check_Login(Model.CustomerData Cusdata) { Service.SQLCustomerCheck SAC = new Service.SQLCustomerCheck(); List <Model.CustomerData> Data = new List <Model.CustomerData>(); Data = SAC.Check(Cusdata); if (Data.Count > 0) { if (Data[0].Customer_Password == Cusdata.Customer_Password) { HttpCookie cook = new HttpCookie("cookie"); cook["Account"] = Cusdata.Customer_Email.ToString(); Response.Cookies.Add(cook); @ViewBag.show = cook["Account"].ToString(); } else { @ViewBag.show = "帳號或密碼錯誤"; } } else { @ViewBag.show = "帳號或密碼錯誤"; } @ViewBag.result = Data; return(View()); }
public Boolean Update(Model.CustomerData Data) { string sql = "Update dbo.Customer_Data set "; if (Data.Customer_Name != null) { sql += "Customer_Name = '" + Data.Customer_Name + "' , "; } if (Data.Customer_Cellphone != null) { sql += " Customer_Cellphone = '" + Data.Customer_Cellphone + "'"; } if (Data.Customer_Password != null) { sql += "Update dbo.Customer_Account set "; sql += " Customer_Password = '******' where Customer_Email = '" + Data.Customer_Email + "'"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBconn"].ConnectionString); using (conn) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); cmd.ExecuteNonQuery(); conn.Close(); } return(true); }
// GET: DataShow public ActionResult Index(string Order_ID) { int Total = 0; Model.CustomerData Customer_Data = new Model.CustomerData(); List <Model.CustomerOrder> Customer_Order = new List <Model.CustomerOrder>(); List <Model.ShowBook> Book_Data = new List <Model.ShowBook>(); Service.SQLCustomerData SCD = new Service.SQLCustomerData(); Service.SQLGetCustomerOrder SGCO = new Service.SQLGetCustomerOrder(); Service.SQLGetShowBook SGSB = new Service.SQLGetShowBook(); Customer_Data = SCD.getData(Request.Cookies["cookie"]["Account"].ToString()); Customer_Order = SGCO.Get_Customer_Order(Order_ID, Customer_Data.Customer_Email); Book_Data = SGSB.ShowBook(Customer_Order[0].Order_ID.ToString()); ViewBag.Customer_Data = Customer_Data; ViewBag.Customer_Order = Customer_Order; for (int i = 0; i < Book_Data.Count; i++) { Total += int.Parse(Book_Data[i].Book_Price) * int.Parse(Book_Data[i].Order_Quantity); } ViewBag.Book_Data = Book_Data; ViewBag.Price_Total = Total; Service.SQLDeleteShoppingCart SDSC = new Service.SQLDeleteShoppingCart(); SDSC.Delete_Cart(); return(View()); }
private Model.CustomerData FillData(DataTable dt) { Model.CustomerData result = new Model.CustomerData(); foreach (DataRow row in dt.Rows) { result.Customer_Name = row["Customer_Name"].ToString(); result.Customer_Cellphone = row["Customer_Cellphone"].ToString(); result.Customer_Email = row["Customer_Email"].ToString(); } return(result); }
public ActionResult Update(Model.CustomerData Data) { Service.SQLCustomerUpdate SCU = new Service.SQLCustomerUpdate(); Boolean Check = false; Check = SCU.Update(Data); if (Check) { ViewBag.Data = "修改成功!"; } else { ViewBag.Data = "修改失敗!"; } return(View()); }
public Model.CustomerData getData(string Account) { Model.CustomerData Data = new Model.CustomerData(); DataTable dt = new DataTable(); string sql = "select * from dbo.Customer_Data where Customer_Email = '" + Account + "'"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBconn"].ConnectionString); using (conn) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); sqlAdapter.Fill(dt); conn.Close(); } Data = FillData(dt); return(Data); }
public ActionResult Insert(string submitbutton, Model.CustomerData CusData) { switch (submitbutton) { case "已有帳號?": return(RedirectToAction("index", "Login")); case "註冊": HttpCookie cook = new HttpCookie("cookie"); Service.SQLRegistered SSR = new Service.SQLRegistered(); List <Model.CustomerData> Data = new List <Model.CustomerData>(); string get_mail = SSR.Regis(CusData); cook["Account"] = get_mail; Response.Cookies.Add(cook); break; } return(RedirectToAction("index", "Home")); }
// GET: Update public ActionResult Index() { string Account = ""; Service.SQLCustomerData SSC = new Service.SQLCustomerData(); Model.CustomerData Data = new Model.CustomerData(); if (Request.Cookies["cookie"] == null) { return(RedirectToAction("RedirectToLogin", "Login")); } else { Account = Request.Cookies["cookie"]["Account"].ToString(); } Data = SSC.getData(Account); ViewBag.Data = Data; return(View()); }
public string Regis(Model.CustomerData a) { DataTable dt = new DataTable(); bool Data; string name = a.Customer_Name; string cellphone = a.Customer_Cellphone; string Email = a.Customer_Email; string pwd = a.Customer_Password; string sql_check = "select * from Customer_Data where Customer_Email = '" + Email + "';"; string sql = "insert into Customer_Data(Customer_Email,Customer_Name,Customer_Cellphone) values('" + Email + "','" + name + "','" + cellphone + "')"; string sql_pwd = "insert into Customer_Account(Customer_Email,Customer_Password) values('" + Email + "','" + pwd + "')"; string set_Sql = sql + " " + sql_pwd; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBconn"].ConnectionString); using (conn) { conn.Open(); SqlCommand cmd_check = new SqlCommand(sql_check, conn); SqlDataAdapter sqlAdapter_check = new SqlDataAdapter(cmd_check); sqlAdapter_check.Fill(dt); Data = FillData(dt); if (Data == true) { SqlCommand cmd = new SqlCommand(set_Sql, conn); // cmd.Parameters.Add(new SqlParameter(@a, SqlDbType.Int)) SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); cmd.ExecuteNonQuery(); conn.Close(); return(Email); } else { //帳號已存在視窗. conn.Close(); return(null); } } }
public List <Model.CustomerData> Check(Model.CustomerData Cusdata) { string account = Cusdata.Customer_Email; string sql = @"select ca.Customer_Password,cd.Customer_Email from Customer_Data cd join Customer_Account ca on cd.Customer_Email=ca.Customer_Email where cd.Customer_Email = @Customer_Email"; DataTable dt = new DataTable(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBconn"].ConnectionString); using (conn) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); // cmd.Parameters.Add(new SqlParameter(@a, SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@Customer_Email", account)); SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); sqlAdapter.Fill(dt); conn.Close(); } List <Model.CustomerData> Data = new List <Model.CustomerData>(); Data = FillData(dt); return(Data); }