oracle的自带事务

前端之家收集整理的这篇文章主要介绍了oracle的自带事务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
        /// <summary>
        /// 单据提交 00-00正常 00-01提交成功未上传物流文件 01单据不存在 02状态不正确 03没上传物流文件 04单据关闭成功 05已出库 06出库失败 07库存不足 08无dn明细 09校验不通过
        /// </summary>
        /// <param name="dtParameter"></param>
        /// <returns></returns>
        public static string Submit(string dnNo,string computerNo,string isImport,string cacheKey){
            using (OracleConnection conn = new OracleConnection(OracleHelper.InstanceWMS.GetDBString("WMSDB")))
            {
                string Ret = "01";
                if (isImport != "1") {
                    return "09";
                }
                conn.Open();
                OracleTransaction trans = conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                try
                {
                    DataTable dn = Get_DnBill(dnNo);
                    if (dn == null || dn.Rows.Count == 0)
                    {
                        return "01";
                    }
                    string Status = dn.Rows[0]["STATUS"] == DBNull.Value ? "10" : dn.Rows[0]["STATUS"].ToString();
                    //并发拦截
                    if (Status == "10" || Status == "20")
                    {
                        Ret = SubmitDa(dnNo,computerNo,cacheKey,trans);
                        if (Ret == "00-00" || Ret == "00-01")
                        {
                            trans.Commit();
                        }
                        else {
                            trans.Rollback();
                        }
                    }
                    else
                    {
                        Ret = "02";
                    }
                }
                catch (Exception ex)
                {
                    Ret = ex.Message;
                    trans.Rollback();
                }
                return Ret;
            }
        }

        /// <summary>
        /// 提交的数据访问
        /// </summary>
        /// <param name="dnNo"></param>
        /// <param name="computerNo"></param>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        private static string SubmitDa(string dnNo,string cacheKey,OracleTransaction trans){
            string Ret = "01";
            OracleCommand com = trans.Connection.CreateCommand();
            com.Transaction = trans;
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "PKG_DNBILL.PRO_DN_OUTBOUND";
            OracleParameter[] Parames=new OracleParameter[4];
            Parames[0] = new OracleParameter("PS_DN_NO",OracleType.VarChar);
            Parames[0].Direction = ParameterDirection.Input;
            Parames[0].Value = dnNo;
            Parames[1] = new OracleParameter("PS_COMPUTER_NO",OracleType.VarChar);
            Parames[1].Direction = ParameterDirection.Input;
            Parames[1].Value = computerNo;
            Parames[2] = new OracleParameter("PS_CACHEKEY",OracleType.VarChar);
            Parames[2].Direction = ParameterDirection.Input;
            Parames[2].Value = cacheKey;
            Parames[3] = new OracleParameter("PC_RESULT",OracleType.Cursor);
            Parames[3].Direction = ParameterDirection.Output;
            com.Parameters.AddRange(Parames);

            DataTable table = new DataTable();
            OracleDataAdapter da1 = new OracleDataAdapter(com);
            da1.Fill(table);
            if (table != null && table.Rows.Count > 0) {
                Ret = table.Rows[0][0].ToString();
            }
            return Ret;
        }
原文链接:https://www.f2er.com/oracle/211278.html

猜你在找的Oracle相关文章