Ejemplo n.º 1
0
 /// <summary>
 /// get all unitlist
 /// <summary>
 /// <param name=validonly>status is valid</param>
 /// <param name=out emsg>return error message</param>
 ///<returns>details of all unitlist</returns>
 public BindingCollection <modUnitList> GetIList(bool validonly, out string emsg)
 {
     try
     {
         BindingCollection <modUnitList> modellist = new BindingCollection <modUnitList>();
         //Execute a query to read the categories
         string getwhere = validonly == true ? "and status=1" : string.Empty;
         string sql      = "select unit_no,status,update_user,update_time from unit_list where 1=1 " + getwhere + "order by unit_no";
         using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql))
         {
             while (rdr.Read())
             {
                 modUnitList model = new modUnitList();
                 model.UnitNo     = dalUtility.ConvertToString(rdr["unit_no"]);
                 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);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// get table record
 /// <summary>
 /// <param name=unitno>unitno</param>
 /// <param name=out emsg>return error message</param>
 ///<returns>get a record detail of unitlist</returns>
 public modUnitList GetItem(string unitno, out string emsg)
 {
     try
     {
         //Execute a query to read the categories
         string sql = string.Format("select unit_no,status,update_user,update_time from unit_list where unit_no='{0}' order by unit_no", unitno);
         using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql))
         {
             if (rdr.Read())
             {
                 modUnitList model = new modUnitList();
                 model.UnitNo     = dalUtility.ConvertToString(rdr["unit_no"]);
                 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);
     }
 }
Ejemplo n.º 3
0
 private void DBGrid_SelectionChanged(object sender, EventArgs e)
 {
     if (DBGrid.CurrentRow != null)
     {
         modUnitList mod = (modUnitList)DBGrid.CurrentRow.DataBoundItem;
         txtUnitNo.Text          = mod.UnitNo;
         cboStatus.SelectedIndex = Convert.ToInt32(mod.Status);
         FindText = mod.UnitNo;
     }
 }
Ejemplo n.º 4
0
 protected override void Find()
 {
     for (int i = 0; i < DBGrid.Rows.Count; i++)
     {
         modUnitList mod = (modUnitList)DBGrid.Rows[i].DataBoundItem;
         if (mod.UnitNo.CompareTo(FindText) == 0)
         {
             DBGrid.CurrentCell = DBGrid.Rows[i].Cells[0];
             DBGrid_SelectionChanged(null, null);
             return;
         }
     }
 }
Ejemplo n.º 5
0
 protected override bool Save()
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         if (string.IsNullOrEmpty(txtUnitNo.Text.Trim()))
         {
             MessageBox.Show(clsTranslate.TranslateString("Unit No") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtUnitNo.Focus();
             return(false);
         }
         modUnitList mod = new modUnitList(txtUnitNo.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(txtUnitNo.Text, mod, out Util.emsg);
         }
         if (ret)
         {
             Util.ChangeStatus(this, true);
             DBGrid.Enabled = true;
             LoadData();
             FindText = mod.UnitNo;
             Find();
         }
         return(ret);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(false);
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// update a unitlist
 /// <summary>
 /// <param name=unitno>unitno</param>
 /// <param name=mod>model object of unitlist</param>
 /// <param name=out emsg>return error message</param>
 /// <returns>true/false</returns>
 public bool Update(string unitno, modUnitList mod, out string emsg)
 {
     try
     {
         string sql = string.Format("update unit_list set status={0},update_user='******',update_time=getdate() where unit_no='{2}'", mod.Status, mod.UpdateUser, unitno);
         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);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// insert a unitlist
 /// <summary>
 /// <param name=mod>model object of unitlist</param>
 /// <param name=out emsg>return error message</param>
 /// <returns>true/false</returns>
 public bool Insert(modUnitList mod, out string emsg)
 {
     try
     {
         string sql = string.Format("insert into unit_list(unit_no,status,update_user,update_time)values('{0}',{1},'{2}',getdate())", mod.UnitNo, 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);
     }
 }