/// <summary> /// get table record /// <summary> /// <param name=custtype>custtype</param> /// <param name=out emsg>return error message</param> ///<returns>get a record detail of customertype</returns> public modCustomerType GetItem(string custtype, out string emsg) { try { //Execute a query to read the categories string sql = string.Format("select cust_type,status,update_user,update_time from customer_type where cust_type='{0}' order by cust_type", custtype); using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { if (rdr.Read()) { modCustomerType model = new modCustomerType(dalUtility.ConvertToString(rdr["cust_type"]), dalUtility.ConvertToInt(rdr["status"]), dalUtility.ConvertToString(rdr["update_user"]), 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 customertype /// <summary> /// <param name=validonly>status is valid</param> /// <param name=out emsg>return error message</param> ///<returns>details of all customertype</returns> public BindingCollection <modCustomerType> GetIList(bool validonly, out string emsg) { try { BindingCollection <modCustomerType> modellist = new BindingCollection <modCustomerType>(); //Execute a query to read the categories string getwhere = validonly == true ? "and status=1" : string.Empty; string sql = "select cust_type,status,update_user,update_time from customer_type where 1=1 " + getwhere + "order by cust_type"; using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { while (rdr.Read()) { modCustomerType model = new modCustomerType(dalUtility.ConvertToString(rdr["cust_type"]), dalUtility.ConvertToInt(rdr["status"]), dalUtility.ConvertToString(rdr["update_user"]), 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) { modCustomerType mod = (modCustomerType)DBGrid.CurrentRow.DataBoundItem; txtCustType.Text = mod.CustType; cboStatus.SelectedIndex = Convert.ToInt32(mod.Status); FindText = mod.CustType; } }
protected override void Find() { for (int i = 0; i < DBGrid.Rows.Count; i++) { modCustomerType mod = (modCustomerType)DBGrid.Rows[i].DataBoundItem; if (mod.CustType.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(txtCustType.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("cust type") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCustType.Focus(); return(false); } modCustomerType mod = new modCustomerType(txtCustType.Text.Trim(), cboStatus.SelectedIndex, Util.UserId, DateTime.Now); bool ret = false; if (_status == 1) { ret = _dal.Insert(mod, out Util.emsg); } else if (_status == 2) { ret = _dal.Update(txtCustType.Text, mod, out Util.emsg); } if (ret) { Util.ChangeStatus(this, true); DBGrid.Enabled = true; LoadData(); FindText = mod.CustType; 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> /// update a customertype /// <summary> /// <param name=custtype>custtype</param> /// <param name=mod>model object of customertype</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Update(string custtype, modCustomerType mod, out string emsg) { try { string sql = string.Format("update customer_type set status={0},update_user='******',update_time=getdate() where cust_type='{2}'", mod.Status, mod.UpdateUser, custtype); 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> /// insert a customertype /// <summary> /// <param name=mod>model object of customertype</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Insert(modCustomerType mod, out string emsg) { try { string sql = string.Format("insert into customer_type(cust_type,status,update_user,update_time)values('{0}',{1},'{2}',getdate())", mod.CustType, 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> /// get all customertype /// <summary> /// <param name=custtype>custtype</param> /// <param name=out emsg>return error message</param> ///<returns>details of all customertype</returns> public BindingCollection <modCustomerType> GetIList(string custtype, out string emsg) { try { BindingCollection <modCustomerType> modellist = new BindingCollection <modCustomerType>(); //Execute a query to read the categories string sql = string.Format("select cust_type,status,update_user,update_time from customer_type where cust_type='{0}' order by cust_type", custtype); using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { while (rdr.Read()) { modCustomerType model = new modCustomerType(dalUtility.ConvertToString(rdr["cust_type"]), dalUtility.ConvertToInt(rdr["status"]), dalUtility.ConvertToString(rdr["update_user"]), dalUtility.ConvertToDateTime(rdr["update_time"])); modellist.Add(model); } } emsg = null; return(modellist); } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(null); } }