//************************************************************************** /// <Description> /// This method uses to get data from STD_CostElement /// </Description> /// <Inputs> /// ID /// </Inputs> /// <Outputs> /// STD_CostElementVO /// </Outputs> /// <Returns> /// STD_CostElementVO /// </Returns> /// <Authors> /// HungLa /// </Authors> /// <History> /// Tuesday, February 07, 2006 /// </History> /// <Notes> /// </Notes> //************************************************************************** public object GetObjectVO(int pintID) { const string METHOD_NAME = THIS + ".GetObjectVO()"; DataSet dstPCS = new DataSet(); OleDbDataReader odrPCS = null; OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { string strSql = "SELECT " + STD_CostElementTable.COSTELEMENTID_FLD + "," + STD_CostElementTable.CODE_FLD + "," + STD_CostElementTable.NAME_FLD + "," + STD_CostElementTable.ORDERNO_FLD + "," + STD_CostElementTable.PARENTID_FLD + "," + STD_CostElementTable.ISLEAF_FLD + "," + STD_CostElementTable.COSTELEMENTTYPEID_FLD + " FROM " + STD_CostElementTable.TABLE_NAME + " WHERE " + STD_CostElementTable.COSTELEMENTID_FLD + "=" + pintID; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); ocmdPCS = new OleDbCommand(strSql, oconPCS); ocmdPCS.Connection.Open(); odrPCS = ocmdPCS.ExecuteReader(); STD_CostElementVO voCostElement = new STD_CostElementVO(); while (odrPCS.Read()) { voCostElement.CostElementID = int.Parse(odrPCS[STD_CostElementTable.COSTELEMENTID_FLD].ToString().Trim()); voCostElement.Code = odrPCS[STD_CostElementTable.CODE_FLD].ToString().Trim(); voCostElement.Name = odrPCS[STD_CostElementTable.NAME_FLD].ToString().Trim(); voCostElement.OrderNo = int.Parse(odrPCS[STD_CostElementTable.ORDERNO_FLD].ToString().Trim()); voCostElement.CostElementTypeID = int.Parse(odrPCS[STD_CostElementTable.COSTELEMENTTYPEID_FLD].ToString().Trim()); if (!odrPCS[STD_CostElementTable.PARENTID_FLD].Equals(DBNull.Value)) { voCostElement.ParentID = int.Parse(odrPCS[STD_CostElementTable.PARENTID_FLD].ToString().Trim()); } else { voCostElement.ParentID = 0; } if (!odrPCS[STD_CostElementTable.ISLEAF_FLD].Equals(DBNull.Value)) { voCostElement.IsLeaf = int.Parse(odrPCS[STD_CostElementTable.ISLEAF_FLD].ToString().Trim()); } else { voCostElement.IsLeaf = 0; } } return(voCostElement); } catch (OleDbException ex) { throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } catch (Exception ex) { throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex); } finally { if (oconPCS != null) { if (oconPCS.State != ConnectionState.Closed) { oconPCS.Close(); } } } }
//************************************************************************** /// <Description> /// This method uses to update data to STD_CostElement /// </Description> /// <Inputs> /// STD_CostElementVO /// </Inputs> /// <Outputs> /// /// </Outputs> /// <Returns> /// /// </Returns> /// <Authors> /// HungLa /// </Authors> /// <History> /// 09-Dec-2004 /// </History> /// <Notes> /// </Notes> //************************************************************************** public void Update(object pobjObjecVO) { const string METHOD_NAME = THIS + ".Update()"; STD_CostElementVO voCostElement = (STD_CostElementVO)pobjObjecVO; //prepare value for parameters OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); string strSql = "UPDATE STD_CostElement SET " + STD_CostElementTable.CODE_FLD + "= ?" + "," + STD_CostElementTable.NAME_FLD + "= ?" + "," + STD_CostElementTable.ORDERNO_FLD + "= ?" + "," + STD_CostElementTable.PARENTID_FLD + "= ?" + "," + STD_CostElementTable.ISLEAF_FLD + "= ?" + "," + STD_CostElementTable.COSTELEMENTTYPEID_FLD + "= ?" + " WHERE " + STD_CostElementTable.COSTELEMENTID_FLD + "= ?"; ocmdPCS = new OleDbCommand(strSql, oconPCS); ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.CODE_FLD, OleDbType.WChar)); ocmdPCS.Parameters[STD_CostElementTable.CODE_FLD].Value = voCostElement.Code; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.NAME_FLD, OleDbType.WChar)); ocmdPCS.Parameters[STD_CostElementTable.NAME_FLD].Value = voCostElement.Name; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.ORDERNO_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.ORDERNO_FLD].Value = voCostElement.OrderNo; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.PARENTID_FLD, OleDbType.Integer)); if (voCostElement.ParentID > 0) { ocmdPCS.Parameters[STD_CostElementTable.PARENTID_FLD].Value = voCostElement.ParentID; } else { ocmdPCS.Parameters[STD_CostElementTable.PARENTID_FLD].Value = DBNull.Value; } ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.ISLEAF_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.ISLEAF_FLD].Value = voCostElement.IsLeaf; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.COSTELEMENTTYPEID_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.COSTELEMENTTYPEID_FLD].Value = voCostElement.CostElementTypeID; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.COSTELEMENTID_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.COSTELEMENTID_FLD].Value = voCostElement.CostElementID; ocmdPCS.Connection.Open(); ocmdPCS.ExecuteNonQuery(); } catch (OleDbException ex) { if (ex.Errors.Count > 1) { if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE) { throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex); } } else { throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } } catch (InvalidOperationException ex) { throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } catch (Exception ex) { throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex); } finally { if (oconPCS != null) { if (oconPCS.State != ConnectionState.Closed) { oconPCS.Close(); } } } }
public int AddAndReturnID(object pobjObjectVO) { const string METHOD_NAME = THIS + ".AddAndReturnID()"; OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { STD_CostElementVO voCostElement = (STD_CostElementVO)pobjObjectVO; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); string strSql = "INSERT INTO STD_CostElement(" + STD_CostElementTable.CODE_FLD + "," + STD_CostElementTable.NAME_FLD + "," + STD_CostElementTable.ORDERNO_FLD + "," + STD_CostElementTable.PARENTID_FLD + "," + STD_CostElementTable.ISLEAF_FLD + "," + STD_CostElementTable.COSTELEMENTTYPEID_FLD + ")" + "VALUES(?, ?,?,?,?,?)"; strSql += "; SELECT @@IDENTITY as LatestID"; ocmdPCS = new OleDbCommand(strSql, oconPCS); ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.CODE_FLD, OleDbType.WChar)); ocmdPCS.Parameters[STD_CostElementTable.CODE_FLD].Value = voCostElement.Code; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.NAME_FLD, OleDbType.WChar)); ocmdPCS.Parameters[STD_CostElementTable.NAME_FLD].Value = voCostElement.Name; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.ORDERNO_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.ORDERNO_FLD].Value = voCostElement.OrderNo; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.PARENTID_FLD, OleDbType.Integer)); if (voCostElement.ParentID > 0) { ocmdPCS.Parameters[STD_CostElementTable.PARENTID_FLD].Value = voCostElement.ParentID; } else { ocmdPCS.Parameters[STD_CostElementTable.PARENTID_FLD].Value = DBNull.Value; } ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.ISLEAF_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.ISLEAF_FLD].Value = voCostElement.IsLeaf; ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostElementTable.COSTELEMENTTYPEID_FLD, OleDbType.Integer)); ocmdPCS.Parameters[STD_CostElementTable.COSTELEMENTTYPEID_FLD].Value = voCostElement.CostElementTypeID; ocmdPCS.Connection.Open(); return(int.Parse(ocmdPCS.ExecuteScalar().ToString())); } catch (OleDbException ex) { if (ex.Errors.Count > 1) { if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE) { throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex); } else { throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } } else { throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } } catch (InvalidOperationException ex) { throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } catch (Exception ex) { throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex); } finally { if (oconPCS != null) { if (oconPCS.State != ConnectionState.Closed) { oconPCS.Close(); } } } }