Exemplo n.º 1
0
        public JsonResult SendBack()
        {
            var sendBackDate = DateTime.Now;

            if (!DateTime.TryParse(GetQueryString("SendBackDate"), out sendBackDate))
            {
                throw new Formula.Exceptions.BusinessValidationException("请选择退回日期!");
            }

            var listData = JsonHelper.ToList(GetQueryString("ListData"));

            if (listData.Count == 0)
            {
                throw new BusinessException("请选择要操作的行!");
            }

            var    idList = listData.Select(a => a.GetValue("ID"));
            string sql    = string.Format("select * from S_B_PerformanceBond where ID in ('{0}') ", string.Join("','", idList));
            var    dt     = MarketSQLDB.ExecuteDataTable(sql);
            var    list   = FormulaHelper.DataTableToListDic(dt);

            if (list.Exists(d => d.GetValue("FlowPhase") != "End"))
            {
                throw new BusinessException("只有流程【已结束】的单才能退回!");
            }
            if (list.Exists(d => d.GetValue("IsSendBack") != "0"))
            {
                throw new BusinessException("只有【未退回】的单才能退回!");
            }

            sql = string.Format(@"update S_B_PerformanceBond set IsSendBack='1',SendBackUser='******',SendBackUserName='******',SendBackDate='{3}' 
                where ID in ('{0}') and IsSendBack='0' ", string.Join("','", idList), CurrentUserInfo.UserID, CurrentUserInfo.UserName, sendBackDate.ToString("yyyy-MM-dd"));
            MarketSQLDB.ExecuteNonQuery(sql);
            return(Json(""));
        }
Exemplo n.º 2
0
        protected override void AfterSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            var sql = string.Format(@"update T_F_GuaranteeLetterApply set Status='Terminate',Terminator='{1}',TerminatorName='{2}',TerminateDate=getdate() 
                where ID = '{0}' and FlowPhase='End' ", dic.GetValue("GuaranteeLetterID"), dic.GetValue("Terminator"), dic.GetValue("TerminatorName"));

            MarketSQLDB.ExecuteNonQuery(sql);
        }
Exemplo n.º 3
0
        protected override void BeforeSaveDetail(Dictionary <string, string> dic, string subTableName, Dictionary <string, string> detail, List <Dictionary <string, string> > detailList, S_UI_Form formInfo)
        {
            if (subTableName == "ContractSplit")
            {
                var splitValue = 0m;
                decimal.TryParse(detail.GetValue("SplitValue"), out splitValue);
                if (splitValue <= 0)
                {
                    throw new BusinessValidationException("【委外合同金额】必须大于0!");
                }

                var sql = string.Format("select top 1 * from S_EP_SupplierContractConfirm where SubContractDetailID='{0}' order by ID desc", detail.GetValue("OrlID"));
                var dt  = MarketSQLDB.ExecuteDataTable(sql);
                if (dt.Rows.Count > 0)
                {
                    var supplierContractConfirmInfo = FormulaHelper.DataRowToDic(dt.Rows[0]);
                    var totalConfirmValue           = 0m;
                    decimal.TryParse(supplierContractConfirmInfo.GetValue("TotalValue"), out totalConfirmValue);
                    if (splitValue <= totalConfirmValue)
                    {
                        throw new BusinessValidationException(string.Format("【{0}】的委外金额不能小于【{1}】", detail.GetValue("Name"), totalConfirmValue));
                    }
                    double totalProgress = 0;
                    double.TryParse(supplierContractConfirmInfo.GetValue("TotalProgress"), out totalProgress);
                    if (totalProgress >= 1 && splitValue != totalConfirmValue)
                    {
                        throw new BusinessValidationException("委外合同已经确认至100%,【委外合同金额】不能变更!");
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override void AfterSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            var amount            = Convert.ToDecimal(dic.GetValue("Amount"));
            var returnAmountTotal = Convert.ToDecimal(dic.GetValue("ReturnAmountTotal"));
            var status            = "Return";

            if (returnAmountTotal == amount)
            {
                status = "Settle";
            }
            var sql = string.Format(@"update S_B_Bond set ReturnAmountTotal=(select ISNULL(sum(ReturnAmount),0) from S_B_BondReturn where BondID='{0}'), State='{1}' 
where ID='{0}' ", dic.GetValue("BondID"), status);

            MarketSQLDB.ExecuteNonQuery(sql);
        }
Exemplo n.º 5
0
        protected override void BeforeSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            var returnAmount = 0m;

            decimal.TryParse(dic.GetValue("ReturnAmount"), out returnAmount);
            if (returnAmount <= 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("归还金额必须大于0!");
            }

            if (isNew)
            {
                var sql = string.Format(@"select Bond.ID as BondID,
ISNULL(Bond.Amount,0) as Amount,
ISNULL(BondReturn.ReturnAmountTotal,0) as LastReturnAmountTotal
from (select * from S_B_Bond where ID='{0}') Bond
outer apply(select top 1 * from S_B_BondReturn a where Bond.ID=a.BondID order by a.CreateDate desc) BondReturn ",
                                        dic.GetValue("BondID"));
                var dt = MarketSQLDB.ExecuteDataTable(sql);
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("保证金申请不存在!");
                }
                else
                {
                    var dicLast = FormulaHelper.DataRowToDic(dt.Rows[0]);
                    var amount  = Convert.ToDecimal(dicLast.GetValue("Amount"));
                    var lastReturnAmountTotal = Convert.ToDecimal(dicLast.GetValue("LastReturnAmountTotal"));
                    var returnAmountTotal     = lastReturnAmountTotal + returnAmount;
                    if (returnAmountTotal > amount)
                    {
                        throw new Formula.Exceptions.BusinessValidationException("累计还款金额不能大于保证金金额!");
                    }

                    var performanceAmount = amount - returnAmountTotal;

                    dic.SetValue("LastReturnAmountTotal", Math.Round(lastReturnAmountTotal, 2).ToString());
                    dic.SetValue("ReturnAmountTotal", Math.Round(returnAmountTotal, 2).ToString());
                    dic.SetValue("PerformanceAmount", Math.Round(performanceAmount, 2).ToString());
                }
            }
        }
Exemplo n.º 6
0
        public override JsonResult Delete()
        {
            var listIDs = Request["ListIDs"];

            if (String.IsNullOrEmpty(listIDs))
            {
                throw new Formula.Exceptions.BusinessValidationException("请选择要删除的数据!");
            }
            var ids  = listIDs.Split(',');
            var sql  = string.Format(@"select * from S_B_PerformanceBond where ID in ('{0}')", string.Join("','", ids));
            var dt   = MarketSQLDB.ExecuteDataTable(sql);
            var list = FormulaHelper.DataTableToListDic(dt);
            var flag = list.Exists(a => a.GetValue("FlowPhase") == "Processing" || a.GetValue("FlowPhase") == "End");

            if (flag)
            {
                throw new BusinessException("【流程中】或【已结束】的履约保证金不能删除,请确认!");
            }
            sql = string.Format(@"delete from S_B_PerformanceBond where ID in ('{0}')", string.Join("','", ids));
            MarketSQLDB.ExecuteNonQuery(sql);
            return(Json(""));
        }
Exemplo n.º 7
0
        protected override void BeforeSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            var sql = string.Format(@"select * from T_F_GuaranteeLetterApply where ID='{0}' ", dic.GetValue("GuaranteeLetterID"));
            var dt  = MarketSQLDB.ExecuteDataTable(sql);

            if (dt.Rows.Count == 0)
            {
                throw new BusinessException("保函申请单不存在!");
            }
            if (!(dt.Rows[0]["FlowPhase"] != DBNull.Value && dt.Rows[0]["FlowPhase"].ToString() == "End"))
            {
                throw new BusinessException("只有流程【已结束】的单才能解除!");
            }

            if (isNew)
            {
                sql = string.Format(@"select * from T_F_GuaranteeLetterTerminate where GuaranteeLetterID='{0}' ", dic.GetValue("GuaranteeLetterID"));
                dt  = MarketSQLDB.ExecuteDataTable(sql);
                if (dt.Rows.Count > 0)
                {
                    throw new BusinessException("保函已解除,无需重复解除!");
                }
            }
        }
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            if (!isNew)
            {
                Expenses.Logic.BusinessFacade.DataInterfaceFo.ValidateDataSyn("S_SP_Invoice", dic.GetValue("ID"));
            }
            var invoiceValue = 0m;

            decimal.TryParse(dic.GetValue("Amount"), out invoiceValue);
            if (invoiceValue <= 0)
            {
                throw new BusinessValidationException("【开票金额】必须大于0!");
            }

            var sql = string.Format("select top 1 * from S_EP_InvoiceConfirm where InvoiceID='{0}' order by ID desc", dic.GetValue("ID"));
            var dt  = MarketSQLDB.ExecuteDataTable(sql);

            if (dt.Rows.Count > 0)
            {
                var invoiceConfirmInfo = FormulaHelper.DataRowToDic(dt.Rows[0]);
                var totalConfirmValue  = 0m;
                decimal.TryParse(invoiceConfirmInfo.GetValue("TotalValue"), out totalConfirmValue);
                if (invoiceValue <= totalConfirmValue)
                {
                    throw new BusinessValidationException(string.Format("开票金额【{0}】必须大于开票已确认金额【{1}】", invoiceValue, totalConfirmValue.ToString("#0.00")));
                }
                double totalProgress = 0;
                double.TryParse(invoiceConfirmInfo.GetValue("TotalProgress"), out totalProgress);
                if (totalProgress >= 1 && invoiceValue != totalConfirmValue)
                {
                    throw new BusinessValidationException("开票已经确认至100%,【开票金额】不能变更!");
                }
            }

            if (SysParams.Params.GetValue("SubContractConfirmMethod") == "InvoiceConfirm")//委外开票确认
            {
                if (string.IsNullOrEmpty(dic.GetValue("CostUnit")))
                {
                    throw new BusinessValidationException("请选择成本单元!");
                }
            }
            else
            {
                dic.SetValue("CostUnit", string.Empty);
                dic.SetValue("CostUnitName", string.Empty);
            }

            var invoiceDate = DateTime.Now;

            if (string.IsNullOrEmpty(dic.GetValue("InvoiceDate")) || !DateTime.TryParse(dic.GetValue("InvoiceDate"), out invoiceDate))
            {
                throw new BusinessValidationException("请选择开票日期!");
            }
            dic.SetValue("InvoiceDate", invoiceDate.ToString("yyyy-MM-dd"));
            dic.SetValue("BelongYear", invoiceDate.Year.ToString());
            dic.SetValue("BelongQuarter", ((invoiceDate.Month + 2) / 3).ToString());
            dic.SetValue("BelongMonth", invoiceDate.Month.ToString());

            var entity = this.GetEntityByID(dic["ID"]);

            if (entity == null)
            {
                entity = new S_SP_Invoice();
            }
            this.UpdateEntity(entity, dic);
            entity.Save();
        }
        protected override void BeforeDelete(string[] Ids)
        {
            var sql     = string.Format(@"select PaymentCostInfo.ID,
PaymentCostInfo.CostUnitID as CostUnit,
ISNULL(PaymentCostInfo.CostValue,0) as CostValue,
Payment.ID as PaymentID,
Payment.PaymentDate,
Payment.PaymentUser,
Payment.PaymentUserName,
isnull(SupplierContract.TaxRate,0) as TaxRate
from (select * from S_SP_Payment where ID in ('{0}') ) as Payment
inner join S_SP_Payment_CostInfo PaymentCostInfo on Payment.ID=PaymentCostInfo.S_SP_PaymentID
left join S_SP_SupplierContract SupplierContract on Payment.Contract = SupplierContract.ID ", string.Join("','", Ids));
            var dicList = FormulaHelper.DataTableToListDic(MarketSQLDB.ExecuteDataTable(sql));

            foreach (var dic in dicList)
            {
                Expenses.Logic.BusinessFacade.DataInterfaceFo.ValidateDataSyn("S_SP_Payment", dic.GetValue("PaymentID"));
                if (string.IsNullOrEmpty(dic.GetValue("PaymentDate")))
                {
                    throw new Formula.Exceptions.BusinessValidationException("付款日期为空,请确认!");
                }
                CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dic.GetValue("PaymentDate")));

                var dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CostUnit where ID='{0}' ", dic.GetValue("CostUnit")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定的成本单元,无法确认成本");
                }
                var unitDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSNode where ID='{0}' ", unitDic.GetValue("CBSNodeID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的CBS节点,无法确认成本");
                }
                var unitCBSNode = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSInfo where ID='{0}' ", unitDic.GetValue("CBSInfoID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法确认成本");
                }
                var cbsInfoDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                var costDetailDic = new Dictionary <string, object>();

                sql = string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", dic.GetValue("ID"));
                MarketSQLDB.ExecuteNonQuery(sql);
                var cbsInfo = new Expenses.Logic.Domain.S_EP_CBSInfo(cbsInfoDic);
                cbsInfo.SummaryCostValue();
            }

            var cons = this.BusinessEntities.Set <S_SP_Payment>().Where(t => Ids.Contains(t.ID))
                       .Select(t => t.S_SP_SupplierContract).ToList();
            //承兑汇票
            var payMents = this.BusinessEntities.Set <S_SP_Payment>().Where(t => Ids.Contains(t.ID)).ToList();
            //修改承兑汇票支付状态
            var acceptanceBillIDs = new List <string>();

            foreach (var payMent in payMents)
            {
                var billIDs = payMent.S_SP_Payment_AcceptanceBill.Select(a => a.AcceptanceBillID).ToList();
                var tmpList = this.BusinessEntities.Set <S_C_AcceptanceBill>().Where(a => billIDs.Contains(a.ID)).ToList();
                foreach (var tmp in tmpList)
                {
                    tmp.State = "UnPaid";
                }
            }

            this.BusinessEntities.Set <S_FC_CostInfo>().Delete(d => Ids.Contains(d.RelateID));
            foreach (var con in cons)
            {
                con.SumPaymentValue = con.S_SP_Payment.Where(a => !Ids.Contains(a.ID)).Sum(a => a.PaymentValue);
            }
            this.BusinessEntities.SaveChanges();

            var OADB = SQLHelper.CreateSqlHelper(ConnEnum.OfficeAuto);

            OADB.ExecuteNonQuery("Delete from S_FC_CostInfo where RelateID in ('" + string.Join("','", Ids) + "')");
        }
Exemplo n.º 10
0
        private void ToCostInfo(Dictionary <string, string> entity)
        {
            if (string.IsNullOrEmpty(entity.GetValue("PaymentDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("请填写付款日期");
            }
            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(entity.GetValue("PaymentDate")));

            var sql     = string.Format(@"select PaymentCostInfo.ID,
PaymentCostInfo.CostUnitID as CostUnit,
ISNULL(PaymentCostInfo.CostValue,0) as CostValue,
Payment.PaymentDate,
Payment.PaymentUser,
Payment.PaymentUserName,
isnull(SupplierContract.TaxRate,0) as TaxRate
from (select * from S_SP_Payment where ID='{0}') as Payment
inner join S_SP_Payment_CostInfo PaymentCostInfo on Payment.ID=PaymentCostInfo.S_SP_PaymentID
left join S_SP_SupplierContract SupplierContract on Payment.Contract = SupplierContract.ID ", entity.GetValue("ID"));
            var dicList = FormulaHelper.DataTableToListDic(MarketSQLDB.ExecuteDataTable(sql));

            foreach (var dic in dicList)
            {
                var dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CostUnit where ID='{0}' ", dic.GetValue("CostUnit")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定的成本单元,无法确认成本");
                }
                var unitDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSNode where ID='{0}' ", unitDic.GetValue("CBSNodeID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的CBS节点,无法确认成本");
                }
                var unitCBSNode = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSInfo where ID='{0}' ", unitDic.GetValue("CBSInfoID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法确认成本");
                }
                var cbsInfoDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                var costValue      = string.IsNullOrEmpty(dic.GetValue("CostValue")) ? 0m : Convert.ToDecimal(dic.GetValue("CostValue"));
                var taxRate        = string.IsNullOrEmpty(dic.GetValue("TaxRate")) ? 0m : Convert.ToDecimal(dic.GetValue("TaxRate"));
                var taxValue       = costValue / (1 + taxRate) * taxRate;
                var clearCostValue = costValue - taxValue;

                var costDetailDic = new Dictionary <string, object>();
                var subjectDt     = this.MarketSQLDB.ExecuteDataTable(String.Format(@"select * from S_EP_CBSNode with(nolock)
where FullID like '{0}%' order by FullID", unitCBSNode.GetValue("FullID")));
                var subjectNode   = subjectDt.AsEnumerable().FirstOrDefault(c => c["SubjectType"] != null && c["SubjectType"] != DBNull.Value &&
                                                                            c["SubjectType"].ToString() == SubjectType.SubContractCost.ToString());

                if (subjectNode == null)
                {
                    throw new BusinessException("未找到SubjectType为【" + SubjectType.SubContractCost.ToString() + "】的节点");
                }

                var costState = "Finish";
                costDetailDic.SetValue("Name", subjectNode["Name"]);
                costDetailDic.SetValue("CBSFullCode", subjectNode["FullCode"]);
                costDetailDic.SetValue("CBSNodeID", subjectNode["ID"]);
                costDetailDic.SetValue("CBSNodeFullID", subjectNode["FullID"]);
                if (String.IsNullOrEmpty(costDetailDic.GetValue("Name")))
                {
                    costDetailDic.SetValue("Name", "采购分包费");
                }
                costDetailDic.SetValue("Code", subjectNode["Code"]);
                if (String.IsNullOrEmpty(costDetailDic.GetValue("Code")))
                {
                    costDetailDic.SetValue("Code", unitCBSNode.GetValue("Code"));
                }
                costDetailDic.SetValue("CostType", SubjectType.SubContractCost.ToString());
                costDetailDic.SetValue("CBSInfoID", unitDic.GetValue("CBSInfoID"));
                costDetailDic.SetValue("CostUnitID", unitDic.GetValue("ID"));
                costDetailDic.SetValue("SubjectCode", subjectNode["SubjectCode"]);
                costDetailDic.SetValue("RelateID", dic.GetValue("ID"));
                var costDate = String.IsNullOrEmpty(dic.GetValue("PaymentDate")) ? DateTime.Now : Convert.ToDateTime(dic.GetValue("PaymentDate"));
                costDetailDic.SetValue("CostDate", costDate);
                costDetailDic.SetValue("BelongYear", costDate.Year);
                costDetailDic.SetValue("BelongMonth", costDate.Month);
                costDetailDic.SetValue("BelongQuarter", (costDate.Month - 1) / 3 + 1);
                costDetailDic.SetValue("TotalPrice", costValue);
                costDetailDic.SetValue("TaxRate", taxRate);
                costDetailDic.SetValue("TaxValue", taxValue);
                costDetailDic.SetValue("ClearValue", clearCostValue);
                costDetailDic.SetValue("BelongDept", unitCBSNode.GetValue("ChargerDept"));
                costDetailDic.SetValue("BelongDeptName", unitCBSNode.GetValue("ChargerDeptName"));
                costDetailDic.SetValue("BelongUser", unitCBSNode.GetValue("ChargerUser"));
                costDetailDic.SetValue("BelongUserName", unitCBSNode.GetValue("ChargerUserName"));
                costDetailDic.SetValue("State", costState);
                costDetailDic.SetValue("Status", costState);
                costDetailDic.SetValue("CreateUser", dic.GetValue("PaymentUser"));
                costDetailDic.SetValue("CreateUserName", dic.GetValue("PaymentUserName"));
                costDetailDic.SetValue("CreateDate", DateTime.Now);
                sql = string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", dic.GetValue("ID"));
                MarketSQLDB.ExecuteNonQuery(sql);
                costDetailDic.InsertDB(this.MarketSQLDB, "S_EP_CostInfo");
                var cbsInfo = new S_EP_CBSInfo(cbsInfoDic);
                cbsInfo.SummaryCostValue();
            }
        }
Exemplo n.º 11
0
        protected override void OnFlowEnd(T_C_ContractChange entity, S_WF_InsTaskExec taskExec, S_WF_InsDefRouting routing)
        {
            string tmplCode = Request["TmplCode"];
            var    formInfo = baseEntities.Set <S_UI_Form>().SingleOrDefault(c => c.Code == tmplCode);

            if (formInfo == null)
            {
                throw new Exception("没找到编号为【" + tmplCode + "】的表单定义");
            }
            var sqlContract    = @"select * from S_C_ManageContract where ID = '{0}'";
            var sqlChange      = @"select * from T_C_ContractChange where ID = '{0}'";
            var contarct       = MarketSQLDB.ExecuteDataTable(string.Format(sqlContract, entity.ContractID));
            var change         = MarketSQLDB.ExecuteDataTable(string.Format(sqlChange, entity.ID));
            var subTableFields = JsonHelper.ToList(formInfo.Items).Where(c => c.GetValue("ItemType") == "SubTable").ToList();

            foreach (var item in subTableFields)
            {
                var    contractTableName = "S_C_ManageContract" + "_" + item.GetValue("Code");
                var    subTableName      = formInfo.TableName + "_" + item.GetValue("Code");
                string subSql            = "SELECT count(0) as TableCount FROM sysobjects WHERE name='{0}'";
                var    obj = Convert.ToInt32(this.MarketSQLDB.ExecuteScalar(String.Format(subSql, contractTableName)));
                if (obj <= 0)
                {
                    continue;
                }
                if (item.GetValue("Code") == "ReceiptObj")
                {
                    #region 单独更新收款项(特殊逻辑)
                    subSql = "select * from {0} where {1}='{2}'";
                    var data   = this.MarketSQLDB.ExecuteDataTable(String.Format(subSql, subTableName, formInfo.TableName + "ID", entity.ID));
                    var orlIds = string.Empty;
                    foreach (DataRow subItem in data.Rows)
                    {
                        var dic        = Formula.FormulaHelper.DataRowToDic(subItem);
                        var receiptObj = this.GetEntityByID <S_C_ManageContract_ReceiptObj>(dic.GetValue("OrlID"));
                        if (receiptObj != null)
                        {
                            FormulaHelper.UpdateEntity <S_C_ManageContract_ReceiptObj>(receiptObj, dic, false);
                            receiptObj.ResetPlan();
                        }
                        else
                        {
                            receiptObj = new S_C_ManageContract_ReceiptObj();
                            FormulaHelper.UpdateEntity <S_C_ManageContract_ReceiptObj>(receiptObj, dic, false);
                            var contract = this.GetEntityByID <S_C_ManageContract>(entity.ContractID);
                            if (contract == null)
                            {
                                throw new Formula.Exceptions.BusinessValidationException("不存在ID为【" + entity.ContractID + "】的合同,任务执行失败");
                            }
                            receiptObj.ID = FormulaHelper.CreateGuid();
                            receiptObj.S_C_ManageContractID = contract.ID;
                            receiptObj.S_C_ManageContract   = contract;
                            contract.S_C_ManageContract_ReceiptObj.Add(receiptObj);
                            receiptObj.ResetPlan();
                        }
                        receiptObj.SyncSupplementary();
                        orlIds += dic.GetValue("OrlID") + ",";
                    }
                    orlIds = orlIds.TrimEnd(',');
                    var removeObjList = this.BusinessEntities.Set <S_C_ManageContract_ReceiptObj>().Where(c => c.S_C_ManageContractID == entity.ContractID &&
                                                                                                          !orlIds.Contains(c.ID)).ToList();
                    foreach (var removeObj in removeObjList)
                    {
                        removeObj.Delete();
                    }
                    this.BusinessEntities.SaveChanges();
                    #endregion
                }
                else
                {
                    subSql = "delete from {0} where {1}='{2}'";
                    this.MarketSQLDB.ExecuteNonQuery(String.Format(subSql, contractTableName, "S_C_ManageContract" + "ID", entity.ContractID));
                    subSql = "select * from {0} where {1}='{2}'";
                    var data = this.MarketSQLDB.ExecuteDataTable(String.Format(subSql, subTableName, formInfo.TableName + "ID", entity.ID));
                    foreach (DataRow subItem in data.Rows)
                    {
                        var dic = Formula.FormulaHelper.DataRowToDic(subItem);
                        dic.SetValue("ID", FormulaHelper.CreateGuid());
                        dic.SetValue("S_C_ManageContractID", entity.ContractID);
                        dic.InsertDB(this.MarketSQLDB, contractTableName);
                    }
                }
            }
            var synchList = new List <string>();
            foreach (var column in change.Columns)
            {
                if (!noNeedSynch.Contains(column.ToString()) && contarct.Columns.Contains(column.ToString()))
                {
                    synchList.Add(column.ToString());
                }
            }
            var sql    = @"update S_C_ManageContract set {0} where ID = '{1}'";
            var setStr = " ";
            foreach (var column in synchList)
            {
                setStr += String.Format("{0} = '{1}',", column, change.Rows[0][column]);
            }
            sql = string.Format(sql, setStr.TrimEnd(','), entity.ContractID);
            MarketSQLDB.ExecuteNonQuery(sql);

            #region 自动同步核算项目
            var dt = MarketSQLDB.ExecuteDataTable(string.Format(sqlContract, entity.ContractID));
            if (dt.Rows.Count > 0)
            {
                var contractDic = FormulaHelper.DataRowToDic(dt.Rows[0]);
                Expenses.Logic.CBSInfoFO.SynCBSInfo(contractDic, Expenses.Logic.SetCBSOpportunity.Contract);
            }
            #endregion
        }
Exemplo n.º 12
0
        protected override void OnFlowEnd(T_SP_ContractChange entity, S_WF_InsTaskExec taskExec, S_WF_InsDefRouting routing)
        {
            string tmplCode = Request["TmplCode"];
            var    formInfo = baseEntities.Set <S_UI_Form>().SingleOrDefault(c => c.Code == tmplCode);

            if (formInfo == null)
            {
                throw new Exception("没找到编号为【" + tmplCode + "】的表单定义");
            }
            var sqlContract    = @"select * from S_SP_SupplierContract where ID = '{0}'";
            var sqlChange      = @"select * from T_SP_ContractChange where ID = '{0}'";
            var contract       = MarketSQLDB.ExecuteDataTable(string.Format(sqlContract, entity.ContractID));
            var change         = MarketSQLDB.ExecuteDataTable(string.Format(sqlChange, entity.ID));
            var subTableFields = JsonHelper.ToList(formInfo.Items).Where(c => c.GetValue("ItemType") == "SubTable").ToList();

            foreach (var item in subTableFields)
            {
                var    contractTableName = "S_SP_SupplierContract" + "_" + item.GetValue("Code");
                var    subTableName      = formInfo.TableName + "_" + item.GetValue("Code");
                string subSql            = "SELECT count(0) as TableCount FROM sysobjects WHERE name='{0}'";
                var    obj = Convert.ToInt32(this.MarketSQLDB.ExecuteScalar(String.Format(subSql, contractTableName)));
                if (obj <= 0)
                {
                    continue;
                }
                subSql = "delete from {0} where {1}='{2}'";
                this.MarketSQLDB.ExecuteNonQuery(String.Format(subSql, contractTableName, "S_SP_SupplierContract" + "ID", entity.ContractID));
                subSql = "select * from {0} where {1}='{2}'";
                var data = this.MarketSQLDB.ExecuteDataTable(String.Format(subSql, subTableName, formInfo.TableName + "ID", entity.ID));
                foreach (DataRow subItem in data.Rows)
                {
                    var dic = Formula.FormulaHelper.DataRowToDic(subItem);
                    if (subItem["OrlID"] == null || subItem["OrlID"] == DBNull.Value || String.IsNullOrEmpty(subItem["OrlID"].ToString()))
                    {
                        //表示是新增
                        dic.SetValue("ID", FormulaHelper.CreateGuid());
                    }
                    else
                    {
                        dic.SetValue("ID", subItem["OrlID"]);
                    }
                    dic.SetValue("S_SP_SupplierContractID", entity.ContractID);
                    dic.InsertDB(this.MarketSQLDB, contractTableName, dic.GetValue("ID"));
                }
            }
            var synchList = new List <string>();

            foreach (var column in change.Columns)
            {
                if (!noNeedSynch.Contains(column.ToString()) && contract.Columns.Contains(column.ToString()))
                {
                    synchList.Add(column.ToString());
                }
            }
            var sql    = @"update S_SP_SupplierContract set {0} where ID = '{1}'";
            var setStr = " ";

            foreach (var column in synchList)
            {
                if (column == "SerialNumber")
                {
                    setStr += String.Format("{0} = '{1}',", "SerialNumber", change.Rows[0]["ContractCode"]);
                    continue;
                }
                setStr += String.Format("{0} = '{1}',", column, change.Rows[0][column]);
            }

            sql = string.Format(sql, setStr.TrimEnd(','), entity.ContractID);
            MarketSQLDB.ExecuteNonQuery(sql);
        }