示例#1
0
 private BudModify GetModel(BudModify budModify)
 {
     if (budModify == null)
     {
         budModify           = new BudModify();
         budModify.InputDate = DateTime.Now;
         budModify.InputUser = base.UserCode;
         budModify.Flowstate = -1;
     }
     budModify.ModifyId       = this.hfldBudModifyId.Value.Trim();
     budModify.PrjId          = this.hdnProjectCode.Value;
     budModify.ModifyCode     = this.txtModifyCode.Text.Trim();
     budModify.ModifyContent  = this.txtModifyCode.Text.Trim();
     budModify.ModifyFileCode = this.txtModifyCode.Text.Trim();
     budModify.BudAmount      = 0m;
     budModify.ReportAmount   = 0m;
     budModify.ApprovalAmount = 0m;
     budModify.ApprovalDate   = new DateTime?(DateTime.Now);
     budModify.Note           = string.Empty;
     budModify.InputUser      = base.UserCode;
     budModify.InputDate      = DateTime.Now;
     budModify.LastModifyUser = base.UserCode;
     budModify.LastModifyDate = DateTime.Now;
     return(budModify);
 }
示例#2
0
        public BudTask GetBudTask(string taskId)
        {
            BudModifyService service = new BudModifyService();
            BudModifyTask    byId    = this.GetById(taskId);
            BudTask          task2   = new BudTask();

            if (byId != null)
            {
                BudModify modify = service.GetById(byId.ModifyId);
                task2.TaskId             = byId.ModifyTaskId;
                task2.ParentId           = byId.TaskId;
                task2.OrderNumber        = byId.OrderNumber;
                task2.Version            = 1;
                task2.PrjId              = modify.PrjId;
                task2.TaskCode           = byId.ModifyTaskCode;
                task2.TaskName           = byId.ModifyTaskContent;
                task2.Unit               = byId.Unit;
                task2.Quantity           = new decimal?(byId.Quantity);
                task2.UnitPrice          = new decimal?(byId.UnitPrice);
                task2.Total              = new decimal?(byId.Total);
                task2.StartDate          = byId.StartDate;
                task2.EndDate            = byId.EndDate;
                task2.ConstructionPeriod = byId.ConstructionPeriod;
                task2.Note               = byId.Note;
                task2.InputDate          = DateTime.Now;
                task2.InputUser          = modify.InputUser;
                task2.TaskType           = string.Empty;
                task2.IsValid            = true;
            }
            //List<BudModifyTask> inModifyTask = this.GetInModifyTask(taskId);
            DataSet dsTask = this.GetInModifyTask2(taskId);

            //if (inModifyTask != null)
            if (dsTask.Tables[0].Rows.Count > 0)
            {
                //foreach (BudModifyTask task3 in inModifyTask)
                foreach (DataRow dr in dsTask.Tables[0].Rows)
                {
                    decimal?quantity = task2.Quantity;
                    decimal num3     = Convert.ToDecimal(dr["Quantity"]); //task3.Quantity;
                    task2.Quantity = quantity.HasValue ? new decimal?(quantity.GetValueOrDefault() + num3) : null;
                    decimal?total = task2.Total;
                    decimal num4  = Convert.ToDecimal(dr["Total"]); //task3.Total;
                    task2.Total = total.HasValue ? new decimal?(total.GetValueOrDefault() + num4) : null;
                }
                decimal num  = 0M;
                decimal num2 = 0M;
                if (task2.Total.HasValue)
                {
                    num2 = 0M;
                }
                if (task2.Quantity.HasValue && (task2.Quantity.Value != 0M))
                {
                    num = num2 / task2.Quantity.Value;
                }
                task2.UnitPrice = new decimal?(num);
            }
            return(task2);
        }
示例#3
0
        private List <BudTaskResource> GetAllRes(string prjId, int version)
        {
            List <BudTaskResource> list = (from taskRes in this
                                           join task in this.tSer on taskRes.TaskId equals task.TaskId
                                           where (task.PrjId == prjId) && (task.TaskType == "")
                                           select taskRes).ToList <BudTaskResource>();
            BudModifyTaskResService service  = new BudModifyTaskResService();
            BudModifyTaskService    service2 = new BudModifyTaskService();
            BudModifyService        service3 = new BudModifyService();

            using (List <BudModifyTaskRes> .Enumerator enumerator = (from mtr in service
                                                                     join mt in service2 on mtr.ModifyTaskId equals mt.ModifyTaskId
                                                                     join m in service3 on mt.ModifyId equals m.ModifyId
                                                                     where (m.PrjId == prjId) && (m.Flowstate == 1)
                                                                     select mtr).ToList <BudModifyTaskRes>().GetEnumerator())
            {
                BudModifyTaskRes modifyTaskRes;
                while (enumerator.MoveNext())
                {
                    modifyTaskRes = enumerator.Current;
                    BudModify     byId = service3.GetById(modifyTaskRes.ModifyId);
                    BudModifyTask task = (from mts in service2
                                          where mts.ModifyTaskId == modifyTaskRes.ModifyTaskId
                                          select mts).FirstOrDefault <BudModifyTask>();
                    BudTaskResource item = new BudTaskResource {
                        TaskResourceId = modifyTaskRes.ModifyTaskResId
                    };
                    if (task.ModifyType == 0)
                    {
                        item.TaskId = modifyTaskRes.ModifyTaskId;
                    }
                    else
                    {
                        item.TaskId = task.TaskId;
                    }
                    item.ResourceId       = modifyTaskRes.ResourceId;
                    item.ResourceQuantity = new decimal?(modifyTaskRes.ResourceQuantity);
                    item.ResourcePrice    = new decimal?(modifyTaskRes.ResourcePrice);
                    item.InputDate        = DateTime.Now;
                    item.InputUser        = byId.InputUser;
                    item.PrjGuid          = prjId;
                    item.Versions         = new int?(version);
                    list.Add(item);
                }
            }
            return(list);
        }
示例#4
0
    private void BindModifyInfo()
    {
        BudModify byId = this.modifySer.GetById(this.hfldModifyId.Value);

        if (byId != null)
        {
            this.txtModifyCode.Text     = byId.ModifyCode;
            this.txtModifyContent.Text  = byId.ModifyContent;
            this.txtModifyFileCode.Text = byId.ModifyFileCode;
            this.txtReportAmount.Text   = byId.ReportAmount.ToString();
            this.txtApprovalAmount.Text = byId.ApprovalAmount.ToString();
            if (byId.ApprovalDate.HasValue)
            {
                this.txtApprovalDate.Text = byId.ApprovalDate.Value.ToString("yyyy-MM-dd");
            }
            this.txtNotes.Text = byId.Note;
        }
    }
示例#5
0
    private BudModify GetModel(BudModify budModify)
    {
        if (budModify == null)
        {
            budModify           = new BudModify();
            budModify.InputDate = System.DateTime.Now;
            budModify.InputUser = base.UserCode;
            budModify.Flowstate = -1;
        }
        budModify.ModifyId       = this.hfldModifyId.Value.Trim();
        budModify.PrjId          = this.prjId;
        budModify.ModifyCode     = this.txtModifyCode.Text.Trim();
        budModify.ModifyContent  = this.txtModifyContent.Text.Trim();
        budModify.ModifyFileCode = this.txtModifyFileCode.Text.Trim();
        budModify.BudAmount      = 0m;
        decimal reportAmount = 0m;

        if (!string.IsNullOrEmpty(this.txtReportAmount.Text.Trim()))
        {
            reportAmount = System.Convert.ToDecimal(this.txtReportAmount.Text.Trim());
        }
        budModify.ReportAmount = reportAmount;
        decimal approvalAmount = 0m;

        if (!string.IsNullOrEmpty(this.txtApprovalAmount.Text.Trim()))
        {
            approvalAmount = System.Convert.ToDecimal(this.txtApprovalAmount.Text.Trim());
        }
        budModify.ApprovalAmount = approvalAmount;
        if (!string.IsNullOrEmpty(this.txtApprovalDate.Text.Trim()))
        {
            budModify.ApprovalDate = new System.DateTime?(System.Convert.ToDateTime(this.txtApprovalDate.Text.Trim()));
        }
        budModify.Note           = this.txtNotes.Text.Trim();
        budModify.LastModifyUser = base.UserCode;
        budModify.LastModifyDate = System.DateTime.Now;
        return(budModify);
    }
示例#6
0
        public void CommitEvent(object key)
        {
            BudModifyService       service  = new BudModifyService();
            BudTaskService         service2 = new BudTaskService();
            BudModifyTaskService   service3 = new BudModifyTaskService();
            BudTaskResourceService service4 = new BudTaskResourceService();
            ConPayoutModifyService service5 = new ConPayoutModifyService();
            string    modifyId  = key.ToString();
            BudModify budmodify = (from r in service
                                   where r.ModifyId == modifyId
                                   select r).FirstOrDefault <BudModify>();
            ConPayoutModify item = (from r in service5
                                    where r.BudModifyId == modifyId
                                    select r).FirstOrDefault <ConPayoutModify>();

            if (item != null)
            {
                item.FlowState = 1;
                service5.Update(item);
            }
            using (List <BudModifyTask> .Enumerator enumerator = (from p in service3
                                                                  where p.ModifyId == budmodify.ModifyId
                                                                  select p).ToList <BudModifyTask>().GetEnumerator())
            {
                BudModifyTask taskx;
                while (enumerator.MoveNext())
                {
                    taskx = enumerator.Current;
                    cn.justwin.Domain.Entities.BudTask task = (from p in service2
                                                               where p.TaskId == taskx.TaskId
                                                               select p).FirstOrDefault <cn.justwin.Domain.Entities.BudTask>();
                    if ((task != null) && (budmodify.Flowstate == 1))
                    {
                        if (taskx.ModifyType == 0)
                        {
                            task.IsValid = true;
                            service2.Update(task);
                            service3.UpdateTotal2(taskx.ModifyTaskId);
                        }
                        if ((task.ModifyId != task.ModifyId) || (taskx.ModifyType == 1))
                        {
                            task.ModifyId = task.ModifyId;
                            if (!task.Total2.HasValue)
                            {
                                task.Total2 = 0;
                            }
                            if (!task.Quantity.HasValue)
                            {
                                task.Quantity = 0;
                            }
                            task.Total2   = new decimal?(Convert.ToDecimal(task.Total2) + Convert.ToDecimal(task.Total2));
                            task.Quantity = new decimal?(Convert.ToDecimal(task.Quantity) + Convert.ToDecimal(task.Quantity));
                            if (task.Quantity != 0M)
                            {
                                task.UnitPrice = task.Total2 / task.Quantity;
                            }
                            service2.Update(task);
                            service3.UpdateTotal2(taskx.ModifyTaskId);
                        }
                    }
                }
            }
            if (ConfigHelper.Get("BudgetRequireDiff") != "0")
            {
                string    str2 = ConfigHelper.Get("IsWBSRelevance");
                BudModify byId = service.GetById(key.ToString());
                service2.DeleteYearMonthByPrj(byId.PrjId);
                IList <cn.justwin.Domain.Entities.BudTask> byProject = service2.GetByProject(byId.PrjId, 0x3e7);
                IList <int> years = service2.GetYears(byId.PrjId);
                if (years != null)
                {
                    foreach (int num in years)
                    {
                        IList <cn.justwin.Domain.Entities.BudTask> yearTask = service2.GetYearTask(byProject, num);
                        foreach (cn.justwin.Domain.Entities.BudTask task2 in yearTask)
                        {
                            service2.Add(task2);
                        }
                        foreach (int num2 in service2.GetMonths(yearTask, num))
                        {
                            foreach (cn.justwin.Domain.Entities.BudTask task3 in service2.GetMonthTasks(yearTask, num, num2))
                            {
                                service2.Add(task3);
                            }
                        }
                    }
                    if (str2 == "1")
                    {
                        service4.AddTaskResource(byId.PrjId);
                    }
                }
            }
        }
示例#7
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int count = (
            from modify in this.modifySer
            where modify.PrjId == this.hdnProjectCode.Value.Trim() && modify.ModifyCode == this.txtModifyCode.Text.Trim()
            select modify).ToList <BudModify>().Count;

        if (string.Compare(this.action, "Add", true) == 0)
        {
            if (count > 0)
            {
                base.RegisterScript("top.ui.show('此编码已经存在!');");
                return;
            }
            this.AddContractModify();
            ConPayoutModifyService conPayoutModifyService = new ConPayoutModifyService();
            ConPayoutModify        byId = conPayoutModifyService.GetById(this.hfldModifyId.Value);
            byId.BudModifyId = this.hfldBudModifyId.Value;
            conPayoutModifyService.Update(byId);
            try
            {
                BudModify model = this.GetModel(null);
                this.modifySer.Add(model);
                this.SaveModifyTask();
                this.SaveTask();
                if (this.hfldIsWBSRelevance.Value == "0")
                {
                    this.SaveModifyTaskResByModifyId(this.hfldModifyId.Value);
                }
                base.RegisterScript("top.ui.tabSuccess({ parentName: 'ModifyEdit' });");
                return;
            }
            catch
            {
                base.RegisterScript("top.ui.show('添加失败!');");
                return;
            }
        }
        if (string.Compare(this.action, "Update", true) == 0)
        {
            this.UpdateContractModify();
            BudModify byId2 = this.modifySer.GetById(this.hfldBudModifyId.Value);
            if (byId2 != null && byId2.ModifyCode != this.txtModifyCode.Text.Trim() && count > 0)
            {
                base.RegisterScript("top.ui.show('此编码已经存在!');");
                return;
            }
            try
            {
                this.modifySer.Update(this.GetModel(byId2));
                this.modifyTaskSer.DelModifyTask(this.hfldBudModifyId.Value);
                this.SaveModifyTask();
                this.SaveTask();
                if (this.hfldIsWBSRelevance.Value == "0")
                {
                    this.SaveModifyTaskResByModifyId(this.hfldBudModifyId.Value);
                }
                base.RegisterScript("top.ui.tabSuccess({ parentName: 'ModifyEdit'});");
            }
            catch
            {
                base.RegisterScript("top.ui.show('编辑失败!');");
            }
        }
    }
示例#8
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        List <string> listFromJson = JsonHelper.GetListFromJson(this.hfldModifyId.Value);

        foreach (string modifyId in listFromJson)
        {
            ConPayoutModify payOutModify = (
                from r in this.payOutSer
                where r.ModifyID == modifyId
                select r).FirstOrDefault <ConPayoutModify>();
            BudModify budModify = (
                from r in this.modifySer
                where r.ModifyId == payOutModify.BudModifyId
                select r).FirstOrDefault <BudModify>();
            if (budModify != null)
            {
                List <BudTask> list = (
                    from r in this.budTaskSer
                    where r.ModifyId == budModify.ModifyId
                    select r).ToList <BudTask>();
                foreach (BudTask model in list)
                {
                    BudModifyTask budModifyTask = (
                        from r in this.budModifyTaskSer
                        where r.TaskId == model.TaskId
                        select r).FirstOrDefault <BudModifyTask>();
                    if (budModifyTask.ModifyType == 0)
                    {
                        this.budTaskSer.Delete(model);
                        this.budModifyTaskSer.UpdateTotal2(budModifyTask.ModifyTaskId);
                        this.budModifyTaskSer.Delete(budModifyTask);
                    }
                    else
                    {
                        model.ModifyId  = budModifyTask.ModifyId;
                        model.Total2   -= budModifyTask.Total2;
                        model.Quantity -= budModifyTask.Quantity;
                        if (model.Quantity != 0m)
                        {
                            model.UnitPrice = model.Total2 / model.Quantity;
                        }
                        this.budTaskSer.Update(model);
                        this.budModifyTaskSer.UpdateTotal2(budModifyTask.ModifyTaskId);
                        this.budModifyTaskSer.Delete(budModifyTask);
                    }
                }
                this.modifySer.Delete(budModify);
            }
        }
        try
        {
            //foreach (string current in listFromJson)
            //{
            //	SelfEventAction.SuperDelete(current, "Con_Payout_Modify", "FlowState");
            //}
            this.payoutModify.Delete(listFromJson);
            base.RegisterScript("window.location = window.location;");
        }
        catch (Exception)
        {
            base.RegisterScript("alert('系统提示:\\n\\n删除失败!');");
        }
    }
示例#9
0
    protected void btnSave_Click(object sender, System.EventArgs e)
    {
        int count = (
            from modify in this.modifySer
            where modify.PrjId == this.hfldPrjId.Value.Trim() && modify.ModifyCode == this.txtModifyCode.Text.Trim()
            select modify).ToList <BudModify>().Count;

        if (this.action == "Add")
        {
            if (count > 0)
            {
                base.RegisterScript("top.ui.show('此编码已经存在!');");
                return;
            }
            if (!string.IsNullOrEmpty(this.txtModifyFileCode.Text.Trim()))
            {
                int count2 = (
                    from modify in this.modifySer
                    where modify.ModifyFileCode == this.txtModifyFileCode.Text.Trim()
                    select modify).ToList <BudModify>().Count;
                if (count2 > 0)
                {
                    base.RegisterScript("top.ui.show('此变更文件编号已经存在!');");
                    return;
                }
            }
            try
            {
                BudModify model = this.GetModel(null);
                this.modifySer.Add(model);
                this.SaveOutModifyTask();
                this.SaveInModifyTask();
                if (this.hfldIsWBSRelevance.Value == "0")
                {
                    this.SaveModifyTaskResByModifyId(this.hfldModifyId.Value);
                }
                base.RegisterScript("top.ui.tabSuccess({ parentName: '_EditModify' });");
                return;
            }
            catch
            {
                base.RegisterScript("top.ui.show('添加失败!');");
                return;
            }
        }
        BudModify byId = this.modifySer.GetById(this.hfldModifyId.Value);

        if (byId != null && byId.ModifyCode != this.txtModifyCode.Text.Trim() && count > 0)
        {
            base.RegisterScript("top.ui.show('此编码已经存在!');");
            return;
        }
        if (!string.IsNullOrEmpty(this.txtModifyFileCode.Text.Trim()))
        {
            int count3 = (
                from modify in this.modifySer
                where modify.ModifyFileCode == this.txtModifyFileCode.Text.Trim()
                select modify).ToList <BudModify>().Count;
            if (byId.ModifyFileCode != this.txtModifyFileCode.Text.Trim() && count3 > 0)
            {
                base.RegisterScript("top.ui.show('此变更文件编号已经存在!');");
                return;
            }
        }
        try
        {
            this.modifySer.Update(this.GetModel(byId));
            this.modifyTaskSer.DelModifyTask(this.hfldModifyId.Value);
            this.SaveOutModifyTask();
            this.SaveInModifyTask();
            if (this.hfldIsWBSRelevance.Value == "0")
            {
                this.SaveModifyTaskResByModifyId(this.hfldModifyId.Value);
            }
            base.RegisterScript("top.ui.tabSuccess({ parentName: '_EditModify' });");
        }
        catch
        {
            base.RegisterScript("top.ui.show('编辑失败!');");
        }
    }
示例#10
0
        public IList <BudTask> GetByProject(string prjId, int level = 0x3e7)
        {
            int            orderNumberLen = level * 3;
            List <BudTask> source         = (from t in this
                                             where ((t.PrjId == prjId) && (t.TaskType == string.Empty)) && (t.OrderNumber.Length <= orderNumberLen)
                                             orderby t.OrderNumber
                                             select t).ToList <BudTask>();
            BudModifyTaskService service  = new BudModifyTaskService();
            BudModifyService     service2 = new BudModifyService();

            foreach (BudModifyTask task in (from mt in service
                                            join m in service2 on mt.ModifyId equals m.ModifyId
                                            where ((m.PrjId == prjId) && (m.Flowstate == 1)) && (mt.ModifyType == 0)
                                            select mt).ToList <BudModifyTask>())
            {
                BudModify byId = service2.GetById(task.ModifyId);
                BudTask   item = new BudTask {
                    TaskId             = task.ModifyTaskId,
                    ParentId           = task.TaskId,
                    OrderNumber        = task.OrderNumber,
                    Version            = 1,
                    PrjId              = prjId,
                    TaskCode           = task.ModifyTaskCode,
                    TaskName           = task.ModifyTaskContent,
                    Unit               = task.Unit,
                    Quantity           = new decimal?(task.Quantity),
                    UnitPrice          = new decimal?(task.UnitPrice),
                    Total              = new decimal?(task.Total),
                    StartDate          = task.StartDate,
                    EndDate            = task.EndDate,
                    ConstructionPeriod = task.ConstructionPeriod,
                    Note               = task.Note,
                    InputDate          = DateTime.Now,
                    InputUser          = byId.InputUser,
                    TaskType           = string.Empty,
                    IsValid            = true
                };
                source.Add(item);
            }
            using (List <BudModifyTask> .Enumerator enumerator2 = (from mt in service
                                                                   join m in service2 on mt.ModifyId equals m.ModifyId
                                                                   where ((m.PrjId == prjId) && (m.Flowstate == 1)) && (mt.ModifyType == 1)
                                                                   select mt).ToList <BudModifyTask>().GetEnumerator())
            {
                Func <BudTask, bool> predicate = null;
                BudModifyTask        modifyTask;
                while (enumerator2.MoveNext())
                {
                    modifyTask = enumerator2.Current;
                    if (predicate == null)
                    {
                        predicate = t => t.TaskId == modifyTask.TaskId;
                    }
                    BudTask task3 = source.Where <BudTask>(predicate).FirstOrDefault <BudTask>();
                    if (task3 != null)
                    {
                        decimal?quantity = task3.Quantity;
                        decimal num      = modifyTask.Quantity;
                        task3.Quantity = quantity.HasValue ? new decimal?(quantity.GetValueOrDefault() + num) : null;
                        decimal?total = task3.Total;
                        decimal num2  = modifyTask.Total;
                        task3.Total = total.HasValue ? new decimal?(total.GetValueOrDefault() + num2) : null;
                    }
                }
            }
            return(source);
        }
示例#11
0
        public void CommitEvent(object key)
        {
            string          primarykey   = key.ToString();
            ConPayoutModify payOutModify = (from r in this.payOutSer
                                            where r.ModifyID == primarykey
                                            select r).FirstOrDefault <ConPayoutModify>();
            BudModify budModify = (from r in this.modifySer
                                   where r.ModifyId == payOutModify.BudModifyId
                                   select r).FirstOrDefault <BudModify>();

            budModify.Flowstate = 1;
            this.modifySer.Update(budModify);
            using (List <BudModifyTask> .Enumerator enumerator = (from p in this.budModifyTaskSer
                                                                  where p.ModifyId == budModify.ModifyId
                                                                  select p).ToList <BudModifyTask>().GetEnumerator())
            {
                BudModifyTask task;
                while (enumerator.MoveNext())
                {
                    task = enumerator.Current;
                    BudTask item = (from p in this.budTaskSer
                                    where p.TaskId == task.TaskId
                                    select p).FirstOrDefault <BudTask>();
                    if ((item != null) && (budModify.Flowstate == 1))
                    {
                        if (task.ModifyType == 0)
                        {
                            item.IsValid = true;
                            this.budTaskSer.Update(item);
                            this.budModifyTaskSer.UpdateTotal2(task.ModifyTaskId);
                        }
                        if (item.ModifyId != task.ModifyId)
                        {
                            item.ModifyId = task.ModifyId;
                            item.Total2  += task.Total2;
                            decimal?quantity = item.Quantity;
                            decimal num      = task.Quantity;
                            item.Quantity = quantity.HasValue ? new decimal?(quantity.GetValueOrDefault() + num) : null;
                            if (item.Quantity != 0M)
                            {
                                item.UnitPrice = item.Total2 / item.Quantity;
                            }
                            this.budTaskSer.Update(item);
                            this.budModifyTaskSer.UpdateTotal2(task.ModifyTaskId);
                        }
                    }
                }
            }
            string cmdText = string.Format(" SELECT * FROM Con_Modify_Stock  where ModifyId='{0}' ", primarykey);

            if (SqlHelper.ExecuteQuery(CommandType.Text, cmdText, null).Rows.Count != 0)
            {
                string    str2   = string.Format("SELECT ModifyStock.*FROM Con_Modify_Stock ModifyStock\r\n                                            INNER JOIN Sm_Purchase_Stock purchaseStock ON ModifyStock.purchaseId=purchaseStock.psid\r\n                                            WHERE ModifyId='{0}'", primarykey);
                DataTable table2 = SqlHelper.ExecuteQuery(CommandType.Text, str2, null);
                string    str3   = string.Format("SELECT purchaseStock.* FROM Sm_Purchase_Stock purchaseStock \r\n                                                  LEFT JOIN (SELECT *FROM Con_Modify_Stock  where ModifyId='{0}') ModifyStock\r\n                                                  ON purchaseStock.psid=ModifyStock.purchaseId\r\n                                                  WHERE purchaseStock.pscode in (SELECT DISTINCT Pscode FROM Con_Modify_Stock WHERE ModifyId='{0}')\r\n                                                  AND ModifyStockId IS NULL", primarykey);
                DataTable table3 = SqlHelper.ExecuteQuery(CommandType.Text, str3, null);
                string    str4   = string.Format("SELECT ModifyStock.* FROM Con_Modify_Stock ModifyStock\r\n                                               LEFT JOIN Sm_Purchase_Stock purchaseStock ON ModifyStock.purchaseId=purchaseStock.psid\r\n                                               WHERE ModifyId='{0}'AND psid IS NULL", primarykey);
                DataTable table4 = SqlHelper.ExecuteQuery(CommandType.Text, str4, null);
                using (SqlConnection connection = new SqlConnection(SqlHelper.ConnectionString))
                {
                    connection.Open();
                    SqlTransaction trans = connection.BeginTransaction();
                    foreach (DataRow row in table2.Rows)
                    {
                        PurchaseStockModel model = new PurchaseStockModel {
                            psid   = row["PurchaseId"].ToString(),
                            sprice = DBHelper.GetDecimal(row["Sprice"]),
                            number = DBHelper.GetDecimal(row["Quantity"]),
                            corp   = DBHelper.GetString(row["Corp"])
                        };
                        if (row["ArrivalDate"] != null)
                        {
                            model.ArrivalDate = row["ArrivalDate"].ToString();
                        }
                        else
                        {
                            model.ArrivalDate = null;
                        }
                        model.pscode = row["Pscode"].ToString();
                        model.scode  = row["Scode"].ToString();
                        this.purchaseSotck.Update(trans, model);
                    }
                    foreach (DataRow row2 in table3.Rows)
                    {
                        this.purchaseSotck.Delete(trans, row2["psid"].ToString());
                    }
                    foreach (DataRow row3 in table4.Rows)
                    {
                        PurchaseStockModel model2 = new PurchaseStockModel {
                            psid   = row3["PurchaseId"].ToString(),
                            sprice = DBHelper.GetDecimal(row3["Sprice"]),
                            number = DBHelper.GetDecimal(row3["Quantity"]),
                            corp   = DBHelper.GetString(row3["Corp"])
                        };
                        if (row3["ArrivalDate"] != null)
                        {
                            model2.ArrivalDate = row3["ArrivalDate"].ToString();
                        }
                        else
                        {
                            model2.ArrivalDate = null;
                        }
                        model2.pscode = row3["Pscode"].ToString();
                        model2.scode  = row3["Scode"].ToString();
                        this.purchaseSotck.Add(trans, model2);
                    }
                    trans.Commit();
                    return;
                }
            }
            string    str5   = string.Format("\r\n\t\t\t\t\t\t\t\t\tSELECT PCode FROM Sm_Purchase purchase\r\n\t\t\t\t\t\t\t\t\tINNER JOIN Con_Payout_Modify payoutModify ON purchase.Contract=payoutModify.ContractId\r\n\t\t\t\t\t\t\t\t\tWHERE ModifyId='{0}' AND purchase.FlowState=1", primarykey);
            DataTable table5 = SqlHelper.ExecuteQuery(CommandType.Text, str5, null);

            if (table5.Rows.Count > 0)
            {
                using (SqlConnection connection2 = new SqlConnection(SqlHelper.ConnectionString))
                {
                    connection2.Open();
                    SqlTransaction transaction2 = connection2.BeginTransaction();
                    foreach (DataRow row4 in table5.Rows)
                    {
                        this.purchaseSotck.DeleteByPscode(transaction2, row4["PCode"].ToString());
                    }
                    transaction2.Commit();
                }
            }
        }