/// <summary> /// get table record /// <summary> /// <param name=custlevel>custlevel</param> /// <param name=out emsg>return error message</param> ///<returns>get a record detail of customerlevel</returns> public modCustomerLevel GetItem(string custlevel, out string emsg) { try { //Execute a query to read the categories string sql = string.Format("select cust_level,description,status,update_user,update_time from customer_level where cust_level='{0}' order by cust_level", custlevel); using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { if (rdr.Read()) { modCustomerLevel model = new modCustomerLevel(); model.CustLevel = dalUtility.ConvertToString(rdr["cust_level"]); model.Description = dalUtility.ConvertToString(rdr["description"]); model.Status = dalUtility.ConvertToInt(rdr["status"]); model.UpdateUser = dalUtility.ConvertToString(rdr["update_user"]); model.UpdateTime = dalUtility.ConvertToDateTime(rdr["update_time"]); emsg = null; return(model); } else { emsg = "Error on read data"; return(null); } } } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(null); } }
/// <summary> /// get all customerlevel /// <summary> /// <param name=custlevel>custlevel</param> /// <param name=out emsg>return error message</param> ///<returns>details of all customerlevel</returns> public BindingCollection <modCustomerLevel> GetIList(string getwhere, out string emsg) { try { BindingCollection <modCustomerLevel> modellist = new BindingCollection <modCustomerLevel>(); //Execute a query to read the categories string sql = "select cust_level,description,status,update_user,update_time from customer_level where 1=1 " + getwhere + " order by cust_level"; using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { while (rdr.Read()) { modCustomerLevel model = new modCustomerLevel(); model.CustLevel = dalUtility.ConvertToString(rdr["cust_level"]); model.Description = dalUtility.ConvertToString(rdr["description"]); model.Status = dalUtility.ConvertToInt(rdr["status"]); model.UpdateUser = dalUtility.ConvertToString(rdr["update_user"]); model.UpdateTime = dalUtility.ConvertToDateTime(rdr["update_time"]); modellist.Add(model); } } emsg = null; return(modellist); } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(null); } }
private void DBGrid_SelectionChanged(object sender, EventArgs e) { if (DBGrid.CurrentRow != null) { modCustomerLevel mod = (modCustomerLevel)DBGrid.CurrentRow.DataBoundItem; txtCustLevel.Text = mod.CustLevel; txtDescription.Text = mod.Description; cboStatus.SelectedIndex = Convert.ToInt32(mod.Status); FindText = mod.CustLevel; } }
protected override void Find() { for (int i = 0; i < DBGrid.Rows.Count; i++) { modCustomerLevel mod = (modCustomerLevel)DBGrid.Rows[i].DataBoundItem; if (mod.CustLevel.CompareTo(FindText) == 0) { DBGrid.CurrentCell = DBGrid.Rows[i].Cells[0]; DBGrid_SelectionChanged(null, null); return; } } }
protected override bool Save() { try { this.Cursor = Cursors.WaitCursor; if (string.IsNullOrEmpty(txtCustLevel.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Cust level") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCustLevel.Focus(); return(false); } modCustomerLevel mod = new modCustomerLevel(); mod.CustLevel = txtCustLevel.Text.Trim(); mod.Description = txtDescription.Text.Trim(); mod.Status = cboStatus.SelectedIndex; mod.UpdateUser = Util.UserId; bool ret = false; if (_status == 1) { ret = _dal.Insert(mod, out Util.emsg); } else if (_status == 2) { ret = _dal.Update(txtCustLevel.Text, mod, out Util.emsg); } if (ret) { Util.ChangeStatus(this, true); DBGrid.Enabled = true; LoadData(); FindText = mod.CustLevel; Find(); } return(ret); } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// insert a customerlevel /// <summary> /// <param name=mod>model object of customerlevel</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Insert(modCustomerLevel mod, out string emsg) { try { string sql = string.Format("insert into customer_level(cust_level,description,status,update_user,update_time)values('{0}','{1}','{2}','{3}',getdate())", mod.CustLevel, mod.Description, mod.Status, mod.UpdateUser); int i = SqlHelper.ExecuteNonQuery(sql); if (i > 0) { emsg = null; return(true); } else { emsg = "Unknown error when ExecuteNonQuery!"; return(false); } } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(false); } }
/// <summary> /// update a customerlevel /// <summary> /// <param name=custlevel>custlevel</param> /// <param name=mod>model object of customerlevel</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Update(string custlevel, modCustomerLevel mod, out string emsg) { try { string sql = string.Format("update customer_level set description='{0}',status='{1}',update_user='******',update_time=getdate() where cust_level='{3}'", mod.Description, mod.Status, mod.UpdateUser, custlevel); int i = SqlHelper.ExecuteNonQuery(sql); if (i > 0) { emsg = null; return(true); } else { emsg = "Unknown error when ExecuteNonQuery!"; return(false); } } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(false); } }