示例#1
0
        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 "
                         + sys_TableAndGroupTable.TABLEANDGROUPID_FLD + ","
                         + sys_TableAndGroupTable.TABLEGROUPID_FLD + ","
                         + sys_TableAndGroupTable.TABLEID_FLD + ","
                         + sys_TableAndGroupTable.TABLEORDER_FLD
                         + " FROM " + sys_TableAndGroupTable.TABLE_NAME
                         + " WHERE " + sys_TableAndGroupTable.TABLEANDGROUPID_FLD + "=" + pintID;

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

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

                sys_TableAndGroupVO objObject = new sys_TableAndGroupVO();

                while (odrPCS.Read())
                {
                    objObject.TableAndGroupID = int.Parse(odrPCS[sys_TableAndGroupTable.TABLEANDGROUPID_FLD].ToString());
                    objObject.TableGroupID    = int.Parse(odrPCS[sys_TableAndGroupTable.TABLEGROUPID_FLD].ToString());
                    objObject.TableID         = int.Parse(odrPCS[sys_TableAndGroupTable.TABLEID_FLD].ToString());
                    objObject.TableOrder      = int.Parse(odrPCS[sys_TableAndGroupTable.TABLEORDER_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();
                    }
                }
            }
        }
示例#2
0
        public void Update(object pobjObjecVO)
        {
            const string METHOD_NAME = THIS + ".Update()";

            sys_TableAndGroupVO objObject = (sys_TableAndGroupVO)pobjObjecVO;

            //prepare value for parameters
            OleDbConnection oconPCS = null;
            OleDbCommand    ocmdPCS = null;

            try
            {
                string strSql = String.Empty;
                strSql = "UPDATE sys_TableAndGroup SET "
                         + sys_TableAndGroupTable.TABLEGROUPID_FLD + "=   ?" + ","
                         + sys_TableAndGroupTable.TABLEID_FLD + "=   ?" + ","
                         + sys_TableAndGroupTable.TABLEORDER_FLD + "=  ?"
                         + " WHERE " + sys_TableAndGroupTable.TABLEANDGROUPID_FLD + "= ?";


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

                ocmdPCS.Parameters.Add(new OleDbParameter(sys_TableAndGroupTable.TABLEGROUPID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[sys_TableAndGroupTable.TABLEGROUPID_FLD].Value = objObject.TableGroupID;

                ocmdPCS.Parameters.Add(new OleDbParameter(sys_TableAndGroupTable.TABLEID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[sys_TableAndGroupTable.TABLEID_FLD].Value = objObject.TableID;

                ocmdPCS.Parameters.Add(new OleDbParameter(sys_TableAndGroupTable.TABLEORDER_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[sys_TableAndGroupTable.TABLEORDER_FLD].Value = objObject.TableOrder;

                ocmdPCS.Parameters.Add(new OleDbParameter(sys_TableAndGroupTable.TABLEANDGROUPID_FLD, OleDbType.Integer));
                ocmdPCS.Parameters[sys_TableAndGroupTable.TABLEANDGROUPID_FLD].Value = objObject.TableAndGroupID;


                ocmdPCS.CommandText = strSql;
                ocmdPCS.Connection.Open();
                ocmdPCS.ExecuteNonQuery();
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE ||
                    ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_UNIQUE_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();
                    }
                }
            }
        }