public bool AcctOaStatus(AcctOAStatusParam pars)
        {
            var token = CommonToken.GetToken();
            var http  = new ArrowInterface.ArrowInterface();

            pars.acctCode = ConfigurationManager.AppSettings["dealerCode"];
            var result = http.AcctOaStatus(token.Token, pars);

            var Helper = new OracleDBHelper();

            if (result.Success)
            {
                foreach (var row in result.Rows.AsParallel())
                {
                    var conn = Helper.GetNewConnection();
                    conn.Open();
                    var tran = conn.BeginTransaction();
                    try
                    {
                        Helper.DeleteWithTran(row, tran);
                        Helper.DeleteWithTran <AcctOAStatusDetailed>($" AND ORDERNO='{row.orderNo}'", tran);
                        Helper.InsertWithTransation(row, tran);
                    }
                    catch (Exception e)
                    {
                        tran.Rollback();
                        conn.Close();
                        var message = $"OA同步结果插入失败:{JsonConvert.SerializeObject(row)}";
                        LogHelper.Info(message);
                        LogHelper.Error(e);
                        return(false);
                    }

                    tran.Commit();
                }
            }


            return(result.Success);
        }
        public bool SaleOrderUpload(List <string> billNos)
        {
            var             auditType = AuditEnums.提交同步;
            ICPOBILLAuditor auditor   = new ICPOBILLAuditor("System", auditType);
            var             err       = auditor.CheckOption(billNos, auditType);



            if (!err.Equals(""))
            {
                throw new ArgumentException(err);
            }

            var token  = CommonToken.GetToken();
            var http   = new ArrowInterface.ArrowInterface();
            var Helper = new OracleDBHelper();

            string where = $" AND LHOUTSYSTEMOD IN ('{string.Join("','", billNos)}')";
            var bills = Helper.GetWithWhereStr <SaleOrderUploadParam>(where);

            bills.ForEach(b =>
            {
                var details = Helper.GetWhere(new SaleOrderUploadDetailedParam()
                {
                    lHOutSystemID = b.lHOutSystemID
                }).ToArray();

                b.saleOrderItemList = details;
            });

            List <string> errors = new List <string>();

            bills.ForEach(b =>
            {
                var conn = Helper.GetNewConnection();
                conn.Open();
                var tran = conn.BeginTransaction();
                try
                {
                    var result = http.SaleOrderUpload(token.Token, b);

                    if (result.Success)
                    {
                        var saleorderRepository = new DefaultRepository <Order>(DBTypeEnums.ORACLE);


                        ///返写箭牌销售单号到本地采购订单表ICPOBILL的FDesBillNo字段
                        var whereStr = $" AND FBILLNO='{b.lHOutSystemOd}'";
                        var icpobill = Helper.GetWithTranWithWhereStr <ICPOBILLMODEL>(whereStr, tran)
                                       .SingleOrDefault();

                        saleorderRepository.Delete(new { lHOutSystemID = b.lHOutSystemID }, tran);

                        foreach (var row in result.item.AsParallel())
                        {
                            Helper.InsertWithTransation(row, tran);

                            icpobill.FDesBillNo = row.orderNo;
                        }

                        //更新本地采购订单表ICPOBILL
                        icpobill.FSTATUS     = (int)ICPOBILLStatus.关闭;
                        icpobill.FSYNCSTATUS = (int)ICPOBILLSyneStatus.已同步;
                        Helper.UpdateWithTransation(icpobill, tran);
                    }
                    else
                    {
                        errors.Add($"单据【{b.lHOutSystemOd}】上传失败:{result.Message}");
                    }

                    tran.Commit();
                    conn.Close();
                }
                catch (Exception e)
                {
                    tran.Rollback();
                    conn.Close();
                    var message = $"销售订单【{b.lHOutSystemOd}】上传失败:{e.Message}";
                    LogHelper.Info(message);
                    LogHelper.Error(e);
                    throw;
                }
            });

            if (errors.Count > 0)
            {
                throw new Exception(string.Join("\r\n", errors));
            }

            return(true);
        }
Example #3
0
        public string SaveClient(ICPOBILLMODEL ICPOBILL, IEnumerable <ICPOBILLENTRYMODEL> ICPOBILLENTRYList)
        {
            OracleDBHelper helper = new OracleDBHelper();
            var            conn   = helper.GetNewConnection();

            conn.Open();
            var tran = conn.BeginTransaction();

            try
            {
                string FID = null;

                #region 执行前检测
                if (!ICPOBILL.FID.IsGuid())
                {
                    ICPOBILLMODEL temp = ICPOBILLDAL.Instance.GetWhere(new { FBILLNO = ICPOBILL.FBILLNO }).FirstOrDefault();

                    if (temp != null && temp.FID != ICPOBILL.FID)
                    {
                        return("采购订单编号重复!");
                    }
                }

                #endregion

                #region 保存主表

                if (!ICPOBILL.FID.IsGuid())
                {
                    FID = Guid.NewGuid().ToString();
                    ICPOBILL.FSTATUS     = 1;
                    ICPOBILL.FSTATE      = 1;
                    ICPOBILL.FBILLERNAME = ICPOBILL.FBILLER;
                    ICPOBILL.FBILLDATE   = DateTime.Now;
                    ICPOBILL.FID         = FID;
                    ICPOBILL.FSYNCSTATUS = 0;
                    helper.InsertWithTransation(ICPOBILL, tran);
                }
                else
                {
                    FID = ICPOBILL.FID;
                    //var model = ICPOBILLDAL.Instance.Get(FID);
                    //model.FCLIENTID = ICPOBILL.FCLIENTID;
                    //model.FREMARK = ICPOBILL.FREMARK;
                    //model.FDATE = ICPOBILL.FDATE;
                    //model.FTELEPHONE = ICPOBILL.FTELEPHONE;
                    //model.Fpricepolicy = ICPOBILL.Fpricepolicy;
                    //model.FPOtype = ICPOBILL.FPOtype;
                    //model.Fnote = ICPOBILL.Fnote;
                    //model.FPREMISEID = ICPOBILL.FPREMISEID;

                    helper.UpdateWithTransation(ICPOBILL, tran);
                }

                #endregion

                #region 保存子表

                //删除明细
                //ICPOBILLENTRYBLL.Instance.DeleteByICPOBILLID(FID);
                helper.DeleteWithTran <ICPOBILLENTRYMODEL>($"AND  FICPOBILLID='{FID}'", tran);

                //保存明细
                foreach (var item in ICPOBILLENTRYList)
                {
                    item.FICPOBILLID = FID;
                    item.FID         = Guid.NewGuid().ToString();

                    helper.InsertWithTransation(item, tran);
                }

                #endregion
                tran.Commit();
                conn.Dispose();
                return(null);
            }
            catch (Exception e)
            {
                tran.Rollback();
                LogHelper.Info("e.Message=" + e.Message);
                throw;
            }
        }