Пример #1
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to add data to CST_STDItemCost
        ///    </Description>
        ///    <Inputs>
        ///        CST_STDItemCostVO
        ///    </Inputs>
        ///    <Outputs>
        ///       newly inserted primarkey value
        ///    </Outputs>
        ///    <Returns>
        ///       void
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///    </Authors>
        ///    <History>
        ///       Thursday, February 09, 2006
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************


        public void Add(object pobjObjectVO)
        {
            const string METHOD_NAME = THIS + ".Add()";

            OleDbConnection oconPCS = null;
            OleDbCommand    ocmdPCS = null;

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

                strSql = "INSERT INTO CST_STDItemCost("
                         + CST_STDItemCostTable.COST_FLD + ","
                         + CST_STDItemCostTable.ROLLUPDATE_FLD + ","
                         + CST_STDItemCostTable.PRODUCTID_FLD + ","
                         + CST_STDItemCostTable.COSTELEMENTID_FLD + ")"
                         + "VALUES(?,?,?,?)";

                ocmdPCS.Parameters.Add(new OleDbParameter(CST_STDItemCostTable.COST_FLD, OleDbType.Decimal));
                ocmdPCS.Parameters[CST_STDItemCostTable.COST_FLD].Value = objObject.Cost;

                ocmdPCS.Parameters.Add(new OleDbParameter(CST_STDItemCostTable.ROLLUPDATE_FLD, OleDbType.Date));
                if (objObject.RollUpDate != DateTime.MinValue)
                {
                    ocmdPCS.Parameters[CST_STDItemCostTable.ROLLUPDATE_FLD].Value = objObject.RollUpDate;
                }
                else
                {
                    ocmdPCS.Parameters[CST_STDItemCostTable.ROLLUPDATE_FLD].Value = DBNull.Value;
                }

                ocmdPCS.Parameters.Add(new OleDbParameter(CST_STDItemCostTable.PRODUCTID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[CST_STDItemCostTable.PRODUCTID_FLD].Value = objObject.ProductID;

                ocmdPCS.Parameters.Add(new OleDbParameter(CST_STDItemCostTable.COSTELEMENTID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[CST_STDItemCostTable.COSTELEMENTID_FLD].Value = objObject.CostElementID;

                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();
                    }
                }
            }
        }
Пример #2
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to get data from CST_STDItemCost
        ///    </Description>
        ///    <Inputs>
        ///        ID
        ///    </Inputs>
        ///    <Outputs>
        ///       CST_STDItemCostVO
        ///    </Outputs>
        ///    <Returns>
        ///       CST_STDItemCostVO
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///    </Authors>
        ///    <History>
        ///       Thursday, February 09, 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 = String.Empty;
                strSql = "SELECT "
                         + CST_STDItemCostTable.STDITEMCOSTID_FLD + ","
                         + CST_STDItemCostTable.COST_FLD + ","
                         + CST_STDItemCostTable.ROLLUPDATE_FLD + ","
                         + CST_STDItemCostTable.PRODUCTID_FLD + ","
                         + CST_STDItemCostTable.COSTELEMENTID_FLD
                         + " FROM " + CST_STDItemCostTable.TABLE_NAME
                         + " WHERE " + CST_STDItemCostTable.STDITEMCOSTID_FLD + "=" + pintID;

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

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

                CST_STDItemCostVO objObject = new CST_STDItemCostVO();

                while (odrPCS.Read())
                {
                    objObject.STDItemCostID = int.Parse(odrPCS[CST_STDItemCostTable.STDITEMCOSTID_FLD].ToString().Trim());
                    objObject.Cost          = Decimal.Parse(odrPCS[CST_STDItemCostTable.COST_FLD].ToString().Trim());
                    if (!odrPCS[CST_STDItemCostTable.ROLLUPDATE_FLD].Equals(DBNull.Value))
                    {
                        objObject.RollUpDate = DateTime.Parse(odrPCS[CST_STDItemCostTable.ROLLUPDATE_FLD].ToString().Trim());
                    }
                    else
                    {
                        objObject.RollUpDate = DateTime.MinValue;
                    }

                    objObject.ProductID     = int.Parse(odrPCS[CST_STDItemCostTable.PRODUCTID_FLD].ToString().Trim());
                    objObject.CostElementID = int.Parse(odrPCS[CST_STDItemCostTable.COSTELEMENTID_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();
                    }
                }
            }
        }