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