public void SubmitUser() { Database db_ = Database.Instance; try { db_.DefaultConnect(); var dicUser = userinfo.user.FieldNotNullAsDictionary(); var dicCoperator = userinfo.coperator.FieldNotNullAsDictionary(); SqlQueryBuilder Insert = new SqlQueryBuilder(new SqlInsert()); //Using Builder string Userquery = Insert.Fields(dicUser.Keys.ToArray()) .Table("User") .GetQueryString(); string Coperatorquery = Insert.Fields(dicCoperator.Keys.ToArray()) .Table("Coperator") .GetQueryString(); //Using Single Tone db_.Transaction(Userquery, dicUser); db_.Transaction(Coperatorquery, dicCoperator); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
private void btnOK_Click(object sender, EventArgs e) { try { db_.DefaultConnect(); string queryProduct = ""; string queryDriver = ""; string driverType = ""; Dictionary <string, dynamic> dicDriver = new Dictionary <string, dynamic>() { { "Working", true } }; Product product = new Product() { Status = "Delivering", TakeDate = DateTime.Now, TakeBy = cboDriver.Text, TakerID = cboDriver.SelectedValue.ToString(), Note = cboDriverType.Text }; SqlQueryBuilder Update = new SqlQueryBuilder(new SqlUpdate()); queryProduct = Update.Fields(product.FieldNotNullAsDictionary().Keys.ToArray()) .Table("Product") .Where("ID = '" + productID + "'") .GetQueryString(); queryDriver = Update.Fields(dicDriver.Keys.ToArray()) .Table(cboDriverType.Text) .Where("ID = '" + product.TakerID + "'") .GetQueryString(); //Using Single Tone db_.Transaction(queryProduct, product.FieldNotNullAsDictionary()); db_.Transaction(queryDriver, dicDriver); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } this.Close(); }
public void DriverIsFree(string driverID, string DriverType) { try { db_.DefaultConnect(); Dictionary <string, dynamic> dicDriver = new Dictionary <string, dynamic>() { { "Working", false } }; SqlQueryBuilder Update = new SqlQueryBuilder(new SqlUpdate()); //Using Builder string query = Update.Fields(dicDriver.Keys.ToArray()) .Table(DriverType) .Where("ID = '" + driverID + "'") .GetQueryString(); //Using Single Tone db_.Transaction(query, dicDriver); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
public void UpdateProduct(Product product) { try { db_.DefaultConnect(); SqlQueryBuilder Update = new SqlQueryBuilder(new SqlUpdate()); //Using Builder string query = Update.Fields(product.FieldNotNullAsDictionary().Keys.ToArray()) .Table("Product") .Where("ID = '" + product.ID + "'") .GetQueryString(); //Using Single Tone db_.Transaction(query, product.FieldNotNullAsDictionary()); RefreshProduct(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
private void cboDriverType_TextChanged(object sender, EventArgs e) { try { db_.DefaultConnect(); SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("*") .Table(cboDriverType.Text) .GetQueryString(); //Using Single Tone var table = db_.Read(query); //driver cboDriver.DataSource = table; cboDriver.DisplayMember = "StaffName"; cboDriver.ValueMember = "ID"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
private void registration_Load(object sender, EventArgs e) { try { db_.DefaultConnect(); SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("*") .Table("UserRole") .GetQueryString(); //Using Single Tone var table = db_.Read(query); if (table.Rows.Count > 0) { cboRole.DataSource = table; cboRole.DisplayMember = "Role"; cboRole.ValueMember = "ID"; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
Product GetProduct(string itemID) { Product product = null; try { db_.DefaultConnect(); SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("*") .Table("Product") .Where("ID = '" + itemID + "'") .GetQueryString(); //Using Single Tone var products_ = db_.Read(query); if (products_.Rows.Count > 0) { product = new Product() { ID = products_.Rows[0].Field <string>("ID"), Name = products_.Rows[0].Field <string>("Name"), Description = products_.Rows[0].Field <string>("Description"), ProductType = products_.Rows[0].Field <string>("ProductType"), SalerID = products_.Rows[0].Field <string>("SalerID"), SalerName = products_.Rows[0].Field <string>("SalerName"), CheckInDate = products_.Rows[0].Field <DateTime?>("CheckInDate"), ToLocation = products_.Rows[0].Field <string>("ToLocation"), CusPhone = products_.Rows[0].Field <string>("CusPhone"), CusAddress = products_.Rows[0].Field <string>("CusAddress"), TakerID = products_.Rows[0].Field <string>("TakerID"), TakeBy = products_.Rows[0].Field <string>("TakeBy"), TakeDate = products_.Rows[0].Field <DateTime?>("TakeDate"), CloseDate = products_.Rows[0].Field <DateTime?>("CloseDate"), Status = products_.Rows[0].Field <string>("Status"), Note = products_.Rows[0].Field <string>("Note") }; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } return(product); }
private void btnAdd_Click(object sender, EventArgs e) { try { db_.DefaultConnect(); var item = new Product() { ID = op.NewID(), Name = tbProductName.Text, Description = tbDescribtion.Text, //ProductType= SalerID = Program.main.user.ID, SalerName = Program.main.user.LastName, CheckInDate = DateTime.Now, ToLocation = tbToLocation.Text, CusPhone = tbCusPhone.Text, CusAddress = tbCusAddress.Text, //TakeBy //TakeDate //CloseDate Status = "Hold", Note = "" }.FieldNotNullAsDictionary(); SqlQueryBuilder Insert = new SqlQueryBuilder(new SqlInsert()); //Using Builder string query = Insert.Fields(item.Keys.ToArray()) .Table("Product") .GetQueryString(); //Using Single Tone db_.Transaction(query, item); RefreshProduct(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
void SampleSelect() { try { db_.DefaultConnect(); SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("") .Table("") .Where("") .GetQueryString(); //Using Single Tone db_.Read(query); } catch (Exception) { } finally { db_.Disconnect(); } }
void LoadUserRole() { try { db_.DefaultConnect(); SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("*") .Table("UserRole") .GetQueryString(); //Using Single Tone var userRoles_ = db_.Read(query); if (userRoles_.Rows.Count > 0) { foreach (DataRow role in userRoles_.Rows) { UserRole userrole = new UserRole() { ID = role.Field <string>("ID"), Role = role.Field <string>("Role"), Desc = role.Field <string>("Desc") }; UserRoles.Add(userrole); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
void SampleUpdate() { Dictionary <string, dynamic> fields = new Dictionary <string, dynamic>(); try { db_.DefaultConnect(); SqlQueryBuilder Update = new SqlQueryBuilder(new SqlUpdate()); //Using Builder string query = Update.Fields(fields.Keys.ToArray()) .Table("") .Where("") .GetQueryString(); //Using Single Tone db_.Transaction(query, fields); } catch (Exception) { } finally { db_.Disconnect(); } }
void RefreshDatasource() { Product product = null; string condition = ""; if (Program.main.user.RoleID != "423DAC41-7E15-4EAC-BAF1-7B2421BE5CBB") //Check RolID != RoleAdmin { condition = "SalerID = '" + Program.main.user.ID + "'"; } try { db_.DefaultConnect(); SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("*") .Table("Product") .Where(condition) .GetQueryString(); //Using Single Tone var product_ = db_.Read(query); if (product_.Rows.Count > 0) { lstProducts = new List <Product>(); foreach (DataRow item in product_.Rows) { product = new Product() { ID = item.Field <string>("ID"), Name = item.Field <string>("Name"), Description = item.Field <string>("Description"), ProductType = item.Field <string>("ProductType"), SalerID = item.Field <string>("SalerID"), SalerName = item.Field <string>("SalerName"), CheckInDate = item.Field <DateTime?>("CheckInDate"), ToLocation = item.Field <string>("ToLocation"), CusPhone = item.Field <string>("CusPhone"), CusAddress = item.Field <string>("CusAddress"), TakerID = item.Field <string>("TakerID"), TakeBy = item.Field <string>("TakeBy"), TakeDate = item.Field <DateTime?>("TakeDate"), CloseDate = item.Field <DateTime?>("CloseDate"), Status = item.Field <string>("Status"), Note = item.Field <string>("Note") }; lstProducts.Add(product); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }
private void btnLogin_Click(object sender, EventArgs e) { try { db_.DefaultConnect(); string userName = tbUserName.Text; string password = tbPassword.Text; SqlQueryBuilder Select = new SqlQueryBuilder(new SqlSelect()); //Using Builder string query = Select.Fields("*") .Table("User") .Where("UserName like '" + userName + "'") .GetQueryString(); //Using Single Tone var table = db_.Read(query); if (table.Rows.Count > 0) { var u = table.Rows[0]; User user = new User() { ID = u.Field <string>("ID"), FirstName = u.Field <string>("FirstName"), LastName = u.Field <string>("LastName"), UserName = u.Field <string>("UserName"), Email = u.Field <string>("Email"), Gender = u.Field <string>("Gender"), password = u.Field <string>("password"), RoleID = u.Field <string>("RoleID"), }; if (user != null) { if (user.password == password) { //Login Success Program.main.user = user; Program.main.OpenMainMenu(); } else { MessageBox.Show("Incorrect Password!"); tbPassword.Text = ""; } } else { MessageBox.Show("UserName not found!"); tbUserName.Text = ""; tbPassword.Text = ""; } } else { MessageBox.Show("UserName not found!"); tbUserName.Text = ""; tbPassword.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { db_.Disconnect(); } }