Exemplo n.º 1
0
        /// <summary>
        /// Gets CostCenterRateMasterVO obejct from ID
        /// </summary>
        /// <param name="pintID">Master ID</param>
        /// <returns>CostCenterRateMasterVO</returns>
        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 "
                         + STD_CostCenterRateMasterTable.COSTCENTERRATEMASTERID_FLD + ","
                         + STD_CostCenterRateMasterTable.CCNID_FLD + ","
                         + STD_CostCenterRateMasterTable.CODE_FLD + ","
                         + STD_CostCenterRateMasterTable.NAME_FLD
                         + " FROM " + STD_CostCenterRateMasterTable.TABLE_NAME
                         + " WHERE " + STD_CostCenterRateMasterTable.COSTCENTERRATEMASTERID_FLD + "=" + pintID;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                ocmdPCS = new OleDbCommand(strSql, oconPCS);

                ocmdPCS.Connection.Open();
                odrPCS = ocmdPCS.ExecuteReader();

                STD_CostCenterRateMasterVO objObject = new STD_CostCenterRateMasterVO();

                while (odrPCS.Read())
                {
                    objObject.CostCenterRateMasterID = int.Parse(odrPCS[STD_CostCenterRateMasterTable.COSTCENTERRATEMASTERID_FLD].ToString().Trim());
                    objObject.CCNID = int.Parse(odrPCS[STD_CostCenterRateMasterTable.CCNID_FLD].ToString().Trim());
                    objObject.Code  = odrPCS[STD_CostCenterRateMasterTable.CODE_FLD].ToString().Trim();
                    objObject.Name  = odrPCS[STD_CostCenterRateMasterTable.NAME_FLD].ToString().Trim();
                }
                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();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public int AddAndReturnID(object pobjObjectVO)
        {
            const string    METHOD_NAME = THIS + ".AddAndReturnID()";
            OleDbConnection oconPCS     = null;
            OleDbCommand    ocmdPCS     = null;

            try
            {
                STD_CostCenterRateMasterVO objObject = (STD_CostCenterRateMasterVO)pobjObjectVO;
                string strSql = String.Empty;
                Utils  utils  = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                ocmdPCS = new OleDbCommand("", oconPCS);

                strSql = "INSERT INTO STD_CostCenterRateMaster("
                         + STD_CostCenterRateMasterTable.CCNID_FLD + ","
                         + STD_CostCenterRateMasterTable.CODE_FLD + ","
                         + STD_CostCenterRateMasterTable.NAME_FLD + ")"
                         + " VALUES(?,?,?)"
                         + "; SELECT @@IDENTITY AS NEWID";

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.CCNID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.CCNID_FLD].Value = objObject.CCNID;

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.CODE_FLD, OleDbType.WChar));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.CODE_FLD].Value = objObject.Code;

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.NAME_FLD, OleDbType.WChar));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.NAME_FLD].Value = objObject.Name;


                ocmdPCS.CommandText = strSql;
                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();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Update(object pobjObjecVO)
        {
            const string METHOD_NAME = THIS + ".Update()";

            STD_CostCenterRateMasterVO objObject = (STD_CostCenterRateMasterVO)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 STD_CostCenterRateMaster SET "
                          + STD_CostCenterRateMasterTable.CCNID_FLD + "=   ?" + ","
                          + STD_CostCenterRateMasterTable.CODE_FLD + "=   ?" + ","
                          + STD_CostCenterRateMasterTable.NAME_FLD + "=  ?"
                          + " WHERE " + STD_CostCenterRateMasterTable.COSTCENTERRATEMASTERID_FLD + "= ?";

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.CCNID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.CCNID_FLD].Value = objObject.CCNID;

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.CODE_FLD, OleDbType.WChar));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.CODE_FLD].Value = objObject.Code;

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.NAME_FLD, OleDbType.WChar));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.NAME_FLD].Value = objObject.Name;

                ocmdPCS.Parameters.Add(new OleDbParameter(STD_CostCenterRateMasterTable.COSTCENTERRATEMASTERID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[STD_CostCenterRateMasterTable.COSTCENTERRATEMASTERID_FLD].Value = objObject.CostCenterRateMasterID;


                ocmdPCS.CommandText = strSql;
                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();
                    }
                }
            }
        }