//************************************************************************** /// <Description> /// This method uses to get data from PO_PurchaseType /// </Description> /// <Inputs> /// ID /// </Inputs> /// <Outputs> /// PO_PurchaseTypeVO /// </Outputs> /// <Returns> /// PO_PurchaseTypeVO /// </Returns> /// <Authors> /// HungLa /// </Authors> /// <History> /// Tuesday, March 01, 2005 /// </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 = String.Empty; strSql = "SELECT " + PO_PurchaseTypeTable.PURCHASETYPEID_FLD + "," + PO_PurchaseTypeTable.CODE_FLD + "," + PO_PurchaseTypeTable.DESCRIPTION_FLD + " FROM " + PO_PurchaseTypeTable.TABLE_NAME + " WHERE " + PO_PurchaseTypeTable.PURCHASETYPEID_FLD + "=" + pintID; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); ocmdPCS = new OleDbCommand(strSql, oconPCS); ocmdPCS.Connection.Open(); odrPCS = ocmdPCS.ExecuteReader(); PO_PurchaseTypeVO objObject = new PO_PurchaseTypeVO(); while (odrPCS.Read()) { objObject.PurchaseTypeID = int.Parse(odrPCS[PO_PurchaseTypeTable.PURCHASETYPEID_FLD].ToString()); objObject.Code = odrPCS[PO_PurchaseTypeTable.CODE_FLD].ToString(); objObject.Description = odrPCS[PO_PurchaseTypeTable.DESCRIPTION_FLD].ToString(); } 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(); } } } }
//************************************************************************** /// <Description> /// This method uses to add data to PO_PurchaseType /// </Description> /// <Inputs> /// PO_PurchaseTypeVO /// </Inputs> /// <Outputs> /// newly inserted primarkey value /// </Outputs> /// <Returns> /// void /// </Returns> /// <Authors> /// HungLa /// </Authors> /// <History> /// Tuesday, March 01, 2005 /// </History> /// <Notes> /// </Notes> //************************************************************************** public void Add(object pobjObjectVO) { const string METHOD_NAME = THIS + ".Add()"; OleDbConnection oconPCS = null; OleDbCommand ocmdPCS = null; try { PO_PurchaseTypeVO objObject = (PO_PurchaseTypeVO)pobjObjectVO; string strSql = String.Empty; Utils utils = new Utils(); oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString); ocmdPCS = new OleDbCommand("", oconPCS); strSql = "INSERT INTO PO_PurchaseType(" + PO_PurchaseTypeTable.CODE_FLD + "," + PO_PurchaseTypeTable.DESCRIPTION_FLD + ")" + "VALUES(?,?)"; ocmdPCS.Parameters.Add(new OleDbParameter(PO_PurchaseTypeTable.CODE_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[PO_PurchaseTypeTable.CODE_FLD].Value = objObject.Code; ocmdPCS.Parameters.Add(new OleDbParameter(PO_PurchaseTypeTable.DESCRIPTION_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[PO_PurchaseTypeTable.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(); } } } }
//************************************************************************** /// <Description> /// This method uses to update data to PO_PurchaseType /// </Description> /// <Inputs> /// PO_PurchaseTypeVO /// </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()"; PO_PurchaseTypeVO objObject = (PO_PurchaseTypeVO)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 PO_PurchaseType SET " + PO_PurchaseTypeTable.CODE_FLD + "= ?" + "," + PO_PurchaseTypeTable.DESCRIPTION_FLD + "= ?" + " WHERE " + PO_PurchaseTypeTable.PURCHASETYPEID_FLD + "= ?"; ocmdPCS.Parameters.Add(new OleDbParameter(PO_PurchaseTypeTable.CODE_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[PO_PurchaseTypeTable.CODE_FLD].Value = objObject.Code; ocmdPCS.Parameters.Add(new OleDbParameter(PO_PurchaseTypeTable.DESCRIPTION_FLD, OleDbType.VarWChar)); ocmdPCS.Parameters[PO_PurchaseTypeTable.DESCRIPTION_FLD].Value = objObject.Description; ocmdPCS.Parameters.Add(new OleDbParameter(PO_PurchaseTypeTable.PURCHASETYPEID_FLD, OleDbType.Integer)); ocmdPCS.Parameters[PO_PurchaseTypeTable.PURCHASETYPEID_FLD].Value = objObject.PurchaseTypeID; 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(); } } } }