/// <summary> /// Регистрация /// </summary> /// <param name="user"></param> /// <returns></returns> public String Regisrg(UserRegistr user) { if (!user.noNull()) { return("Data empty"); } if (CheckReg(user.user.login)) { return("This login is already used"); } MySqlCommand comm = Connection(); String CommStr = "INSERT INTO user (login, password, address, name, last_name) VALUES ('" + user.user.login + "', '" + user.user.password + "', '" + user.address + "', '" + user.name + "', '" + user.last_name + "' );"; try { comm.Connection.Open(); comm.CommandText = CommStr; comm.ExecuteNonQuery(); } catch (MySqlException ex) { return("Error: \r\n{0}" + ex.ToString()); } finally { comm.Connection.Close(); } return("Готово!"); }
public MakeOrder(Controller controller, UserRegistr curUser) { InitializeComponent(); this.controller = controller; this.user = curUser; this.product = controller.LoadProduct(); category = controller.LoadCategory(); //category = new List<UserCategory>(); //int i = 0; //foreach (UserProduct tmpProduct in this.product) //{ // if (i > 1 && category[i - 1].id == tmpProduct.category.id) // { // break; // } // else // { // category.Add(tmpProduct.category); // } // i++; //} listProduct = new Dictionary <UserProduct, int>(); }
private void LoadDataGredOrder(int row) { dataGridOrder.Rows.Clear(); int idUser = (int)dataGridUser.Rows[row].Cells[0].Value; foreach (List <UserOrder> tmpList in order) { if (tmpList.Count != 0) { if (tmpList[0].user.id == idUser) { curUser = tmpList[0].user; foreach (UserOrder tmpOrder in tmpList) { dataGridOrder.Rows.Add(tmpOrder.id, tmpOrder.date, tmpOrder.pickup, tmpOrder.cash); } break; } } else { dataGridOrder.Rows.Add("Пусто"); } } }
public string Registr(UserRegistr user) { Hash hash = new Hash(user.user.password); user.user.password = hash.sum; return(db.Regisrg(user)); }
public Client(UserRegistr user) { Id = user.id; Login = user.user.login; Name = user.name; Address = user.address; Last_name = user.last_name; Order = new List <model.Order>(); }
private int idClient(UserRegistr user) { for (int i = 0; i < client.Count; i++) { if (client[i].Id == user.id) { return(i); } } return(0); }
public List <UserOrder> LoadOrder(UserRegistr user) { List <UserOrder> order; order = db.LoadOrder(user); int i = idClient(user); foreach (UserOrder tmpOrder in order) { client[i].AddOrder(new Order(tmpOrder)); } return(order); }
private void makeOrder_Click(object sender, EventArgs e) { if (status == false) { curUser = user[0]; } MakeOrder makeOrder = new MakeOrder(controller, curUser); DialogResult result = makeOrder.ShowDialog(); if (makeOrder.DialogResult == DialogResult.OK) { MessageBox.Show(makeOrder.result); loadOrder(); LoadDataGredOrder(0); } }
public List <UserOrder> LoadOrder(UserRegistr tmpUser) { List <UserOrder> order = new List <UserOrder>(); String str; MySqlCommand comm = Connection(); String CommOrderStr = "select * from orders where user in (select id from user "; String CommProductStr = "select orders.id, product.*, orders_product.count, category.* from category, orders right join orders_product on orders_product.orders = orders.id right join product on product.id = orders_product.product where product.category = category.id and orders.user in (select id from user "; if (!tmpUser.user.compareAdmin()) { str = "where login = '******');"; } else { str = ")"; } CommOrderStr += str; CommProductStr += str; MySqlDataReader reader; try { comm.Connection.Open(); comm.CommandText = CommOrderStr; reader = comm.ExecuteReader(); while (reader.Read()) { UserOrder tmpOrder; tmpOrder.id = reader.GetInt32(0); tmpOrder.date = reader.GetString(1); tmpOrder.pickup = (reader.GetInt32(3) == 1) ? true : false; tmpOrder.cash = (reader.GetInt32(4) == 1) ? true : false; tmpOrder.user = tmpUser; tmpOrder.product = new Dictionary <UserProduct, int>(); order.Add(tmpOrder); } reader.Close(); comm.CommandText = CommProductStr; reader = comm.ExecuteReader(); while (reader.Read()) { foreach (UserOrder tmpOrder in order) { if (tmpOrder.id == reader.GetInt32(0)) { UserProduct tmpProduct; tmpProduct.id = reader.GetInt32(1); tmpProduct.name = reader.GetString(2); tmpProduct.cost = reader.GetInt32(3); tmpProduct.description = reader.GetString(5); tmpProduct.category.id = reader.GetInt32(7); tmpProduct.category.name = reader.GetString(8); tmpProduct.category.description = reader.GetString(9); tmpOrder.product.Add(tmpProduct, reader.GetInt32(6)); } } } reader.Close(); } catch (MySqlException ex) { Console.WriteLine("Error: \r\n{0}", ex.ToString()); } finally { comm.Connection.Close(); } return(order); }