public object GetObjectVO(string pstrCode) { const string METHOD_NAME = THIS + ".GetObjectVO()"; DataSet dstPCS = new DataSet(); OleDbDataReader odrPCS = null; OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { string strSql = String.Empty; strSql = "SELECT " + ITM_CostCenterTable.COSTCENTERID_FLD + "," + ITM_CostCenterTable.CODE_FLD + "," + ITM_CostCenterTable.NAME_FLD + "," + ITM_CostCenterTable.DESCRIPTION_FLD + " FROM " + ITM_CostCenterTable.TABLE_NAME + " WHERE " + ITM_CostCenterTable.CODE_FLD + "='" + pstrCode + "'"; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); ocmdPCS = new OleDbCommand(strSql, oconPCS); ocmdPCS.Connection.Open(); odrPCS = ocmdPCS.ExecuteReader(); ITM_CostCenterVO objObject = new ITM_CostCenterVO(); while (odrPCS.Read()) { objObject.CostCenterID = int.Parse(odrPCS[ITM_CostCenterTable.COSTCENTERID_FLD].ToString().Trim()); objObject.Code = odrPCS[ITM_CostCenterTable.CODE_FLD].ToString().Trim(); objObject.Name = odrPCS[ITM_CostCenterTable.NAME_FLD].ToString().Trim(); objObject.Description = odrPCS[ITM_CostCenterTable.DESCRIPTION_FLD].ToString().Trim(); } ocmdPCS = null; return(objObject); } 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(); } } } }
public void Update(object pobjObjecVO) { const string METHOD_NAME = THIS + ".Update()"; ITM_CostCenterVO objObject = (ITM_CostCenterVO)pobjObjecVO; //prepare value for parameters OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { string strSql = String.Empty; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); ocmdPCS = new OleDbCommand(strSql, oconPCS); strSql = "UPDATE ITM_CostCenter SET " + ITM_CostCenterTable.CODE_FLD + "= ?" + "," + ITM_CostCenterTable.NAME_FLD + "= ?" + "," + ITM_CostCenterTable.DESCRIPTION_FLD + "= ?" + " WHERE " + ITM_CostCenterTable.COSTCENTERID_FLD + "= ?"; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.CODE_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[ITM_CostCenterTable.CODE_FLD].Value = objObject.Code; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.NAME_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[ITM_CostCenterTable.NAME_FLD].Value = objObject.Name; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.DESCRIPTION_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[ITM_CostCenterTable.DESCRIPTION_FLD].Value = objObject.Description; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.COSTCENTERID_FLD, OleDbType.Integer)); ocmdPCS.Parameters[ITM_CostCenterTable.COSTCENTERID_FLD].Value = objObject.CostCenterID; ocmdPCS.CommandText = strSql; ocmdPCS.Connection.Open(); ocmdPCS.ExecuteNonQuery(); } catch (OleDbException ex) { 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 void Add(object pobjObjectVO) { const string METHOD_NAME = THIS + ".Add()"; OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { ITM_CostCenterVO objObject = (ITM_CostCenterVO)pobjObjectVO; string strSql = String.Empty; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); ocmdPCS = new OleDbCommand("", oconPCS); strSql = "INSERT INTO ITM_CostCenter(" + ITM_CostCenterTable.CODE_FLD + "," + ITM_CostCenterTable.NAME_FLD + "," + ITM_CostCenterTable.DESCRIPTION_FLD + ")" + "VALUES(?,?,?)"; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.CODE_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[ITM_CostCenterTable.CODE_FLD].Value = objObject.Code; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.NAME_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[ITM_CostCenterTable.NAME_FLD].Value = objObject.Name; ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterTable.DESCRIPTION_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[ITM_CostCenterTable.DESCRIPTION_FLD].Value = objObject.Description; ocmdPCS.CommandText = strSql; ocmdPCS.Connection.Open(); ocmdPCS.ExecuteNonQuery(); } catch (OleDbException ex) { 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(); } } } }