Exemplo n.º 1
0
        public void Add(object pobjObjectVO)
        {
            const string METHOD_NAME = THIS + ".Add()";

            OleDbConnection oconPCS = null;
            OleDbCommand    ocmdPCS = null;

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

                strSql = "INSERT INTO MST_BIN("
                         + MST_BINTable.CODE_FLD + ","
                         + MST_BINTable.NAME_FLD + ","
                         + MST_BINTable.LENGTH_FLD + ","
                         + MST_BINTable.WIDTH_FLD + ","
                         + MST_BINTable.HEIGHT_FLD + ","
                         + MST_BINTable.LOCATIONID_FLD + ","
                         + MST_BINTable.LENGTHUNITID_FLD + ","
                         + MST_BINTable.HEIGHTUNITID_FLD + ","
                         + MST_BINTable.WIDTHUNITID_FLD + ")"
                         + "VALUES(?,?,?,?,?,?,?,?,?)";

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

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

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.LENGTH_FLD, OleDbType.Decimal));
                ocmdPCS.Parameters[MST_BINTable.LENGTH_FLD].Value = objObject.Length;

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.WIDTH_FLD, OleDbType.Decimal));
                ocmdPCS.Parameters[MST_BINTable.WIDTH_FLD].Value = objObject.Width;

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.HEIGHT_FLD, OleDbType.Decimal));
                ocmdPCS.Parameters[MST_BINTable.HEIGHT_FLD].Value = objObject.Height;

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.LOCATIONID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[MST_BINTable.LOCATIONID_FLD].Value = objObject.LocationID;

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.LENGTHUNITID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[MST_BINTable.LENGTHUNITID_FLD].Value = objObject.LengthUnitID;

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.HEIGHTUNITID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[MST_BINTable.HEIGHTUNITID_FLD].Value = objObject.HeightUnitID;

                ocmdPCS.Parameters.Add(new OleDbParameter(MST_BINTable.WIDTHUNITID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[MST_BINTable.WIDTHUNITID_FLD].Value = objObject.WidthUnitID;


                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();
                    }
                }
            }
        }
Exemplo n.º 2
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to get data from MST_BIN
        ///    </Description>
        ///    <Inputs>
        ///        ID
        ///    </Inputs>
        ///    <Outputs>
        ///       MST_BINVO
        ///    </Outputs>
        ///    <Returns>
        ///       MST_BINVO
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///       DungLa: Check for null value in database
        ///    </Authors>
        ///    <History>
        ///       Tuesday, January 25, 2005
        ///       18-Mar-2005: DungLa - Check for null value in database
        ///    </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 "
                         + MST_BINTable.BINID_FLD + ","
                         + MST_BINTable.CODE_FLD + ","
                         + MST_BINTable.NAME_FLD + ","
                         + MST_BINTable.LENGTH_FLD + ","
                         + MST_BINTable.WIDTH_FLD + ","
                         + MST_BINTable.HEIGHT_FLD + ","
                         + MST_BINTable.LOCATIONID_FLD + ","
                         + MST_BINTable.LENGTHUNITID_FLD + ","
                         + MST_BINTable.HEIGHTUNITID_FLD + ","
                         + MST_BINTable.WIDTHUNITID_FLD
                         + " FROM " + MST_BINTable.TABLE_NAME
                         + " WHERE " + MST_BINTable.BINID_FLD + "=" + pintID;

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

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

                MST_BINVO objObject = new MST_BINVO();

                while (odrPCS.Read())
                {
                    if (odrPCS[MST_BINTable.BINID_FLD] != DBNull.Value)
                    {
                        objObject.BinID = int.Parse(odrPCS[MST_BINTable.BINID_FLD].ToString().Trim());
                    }
                    objObject.Code = odrPCS[MST_BINTable.CODE_FLD].ToString().Trim();
                    objObject.Name = odrPCS[MST_BINTable.NAME_FLD].ToString().Trim();
                    if (odrPCS[MST_BINTable.LENGTH_FLD] != DBNull.Value)
                    {
                        objObject.Length = Decimal.Parse(odrPCS[MST_BINTable.LENGTH_FLD].ToString().Trim());
                    }
                    if (odrPCS[MST_BINTable.WIDTH_FLD] != DBNull.Value)
                    {
                        objObject.Width = Decimal.Parse(odrPCS[MST_BINTable.WIDTH_FLD].ToString().Trim());
                    }
                    if (odrPCS[MST_BINTable.HEIGHT_FLD] != DBNull.Value)
                    {
                        objObject.Height = Decimal.Parse(odrPCS[MST_BINTable.HEIGHT_FLD].ToString().Trim());
                    }
                    if (odrPCS[MST_BINTable.LOCATIONID_FLD] != DBNull.Value)
                    {
                        objObject.LocationID = int.Parse(odrPCS[MST_BINTable.LOCATIONID_FLD].ToString().Trim());
                    }
                    if (odrPCS[MST_BINTable.LENGTHUNITID_FLD] != DBNull.Value)
                    {
                        objObject.LengthUnitID = int.Parse(odrPCS[MST_BINTable.LENGTHUNITID_FLD].ToString().Trim());
                    }
                    if (odrPCS[MST_BINTable.HEIGHTUNITID_FLD] != DBNull.Value)
                    {
                        objObject.HeightUnitID = int.Parse(odrPCS[MST_BINTable.HEIGHTUNITID_FLD].ToString().Trim());
                    }
                    if (odrPCS[MST_BINTable.WIDTHUNITID_FLD] != DBNull.Value)
                    {
                        objObject.WidthUnitID = int.Parse(odrPCS[MST_BINTable.WIDTHUNITID_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();
                    }
                }
            }
        }