Exemplo n.º 1
0
        /// <summary>
        /// 更新数据
        /// </summary>
        private void UpdateData()
        {
            XMIncludeFields xmNickInclude = null;

            if (ProjectId != 0)
            {
                xmNickInclude = base.XMIncludeFieldsService.GetXMIncludeFieldsListByProjectID(ProjectId);
                if (xmNickInclude == null)
                {
                    base.ShowMessage("请先设置预算字段!");
                    return;
                }
            }

            if (NickID != 0)
            {
                xmNickInclude = base.XMIncludeFieldsService.GetXMIncludeFieldsListByNickID(NickID);
                if (xmNickInclude == null)
                {
                    base.ShowMessage("请先设置预算字段!");
                    return;
                }
            }

            //更新数据
            if (xmNickInclude != null && !string.IsNullOrEmpty(xmNickInclude.Fields))
            {
                string[] parm = xmNickInclude.Fields.Split(',');
                string   pID  = "";           //父节点ID
                string   cID  = "";           //子节点ID
                if (parm != null && parm.Count() > 0)
                {
                    foreach (string id in parm)
                    {
                        var f = base.XMFinancialFieldService.GetXMFinancialFieldById(int.Parse(id));
                        if (f != null)
                        {
                            if (f.ParentID == 0)
                            {
                                pID += f.Id + ",";
                            }
                            else
                            {
                                cID += f.Id + ",";
                            }
                        }
                    }
                }

                if (pID != "" && pID.Length > 0)
                {
                    pID = pID.Substring(0, pID.Length - 1);
                }
                if (cID != "" && cID.Length > 0)
                {
                    cID = cID.Substring(0, cID.Length - 1);
                }
                string[] p = pID.Split(',');
                string[] c = cID.Split(',');
                foreach (string str in p)
                {
                    bool isexsitChild = false;          //是否存在子节点
                    //循环更新12个月
                    for (int i = 1; i <= 12; i++)
                    {
                        decimal total = 0;
                        HozestERP.BusinessLogic.ManageBusiness.XMProjectCostDetail cost = null;
                        if (ProjectId != 0)
                        {
                            cost = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(str), ProjectId, DateTime.Now.Year);
                        }
                        if (NickID != 0)
                        {
                            cost = XMProjectCostDetailService.GetXMProjectCostDataByNick(int.Parse(str), NickID, DateTime.Now.Year);
                        }
                        //var cost = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(str), ProjectId, DateTime.Now.Year);
                        if (cost != null)
                        {
                            var f = base.XMFinancialFieldService.GetXMFinancialFieldByParentID(int.Parse(str));
                            if (f != null && f.Count() > 0)
                            {
                                foreach (string str1 in c)
                                {
                                    foreach (XMFinancialField field in f)
                                    {
                                        if (str1 == field.Id.ToString())
                                        {
                                            isexsitChild = true;
                                            HozestERP.BusinessLogic.ManageBusiness.XMProjectCostDetail d = null;
                                            if (ProjectId != 0)
                                            {
                                                d = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(str), ProjectId, DateTime.Now.Year);
                                            }
                                            if (NickID != 0)
                                            {
                                                d = XMProjectCostDetailService.GetXMProjectCostDataByNick(int.Parse(str), NickID, DateTime.Now.Year);
                                            }
                                            //var d = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(str1), ProjectId, DateTime.Now.Year);
                                            if (d != null)
                                            {
                                                switch (i)
                                                {
                                                case 1:
                                                    total += d.OneMonthCost.Value;
                                                    break;

                                                case 2:
                                                    total += d.TwoMonthCost.Value;
                                                    break;

                                                case 3:
                                                    total += d.ThreeMonthCost.Value;
                                                    break;

                                                case 4:
                                                    total += d.FourMonthCost.Value;
                                                    break;

                                                case 5:
                                                    total += d.FiveMonthCost.Value;
                                                    break;

                                                case 6:
                                                    total += d.SixMonthCost.Value;
                                                    break;

                                                case 7:
                                                    total += d.SevenMonthCost.Value;
                                                    break;

                                                case 8:
                                                    total += d.EightMonthCost.Value;
                                                    break;

                                                case 9:
                                                    total += d.NineMonthCost.Value;
                                                    break;

                                                case 10:
                                                    total += d.TenMonthCost.Value;
                                                    break;

                                                case 11:
                                                    total += d.ElevenMonthCost.Value;
                                                    break;

                                                case 12:
                                                    total += d.TwelMonthCost.Value;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isexsitChild)
                                {
                                    switch (i)
                                    {
                                    case 1:
                                        cost.OneMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 2:
                                        cost.TwoMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 3:
                                        cost.ThreeMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 4:
                                        cost.FourMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 5:
                                        cost.FiveMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 6:
                                        cost.SixMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 7:
                                        cost.SevenMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 8:
                                        cost.EightMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 9:
                                        cost.NineMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 10:
                                        cost.TenMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 11:
                                        cost.ElevenMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;

                                    case 12:
                                        cost.TwelMonthCost = total;
                                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(cost);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        //绑定gridview 控件
        private void BindGrid()
        {
            int           no     = 1;
            int           change = 0;
            StringBuilder str    = new StringBuilder();
            string        year   = ddlYear.SelectedValue;

            if (string.IsNullOrEmpty(this.ProjectId.ToString()))
            {
                base.ShowMessage("项目ID不能为空!");
                return;
            }
            string          includefields = "";
            XMIncludeFields xmNickInclude = null;

            if (this.ProjectId != 0)
            {
                xmNickInclude = base.XMIncludeFieldsService.GetXMIncludeFieldsListByProjectID(this.ProjectId);
            }
            if (this.NickID != 0)
            {
                xmNickInclude = XMIncludeFieldsService.GetXMIncludeFieldsListByNickID(this.NickID);
            }
            //var xmNickInclude = base.XMIncludeFieldsService.GetXMIncludeFieldsListByProjectID(this.ProjectId);
            if (xmNickInclude != null && !string.IsNullOrEmpty(xmNickInclude.Fields))
            {
                includefields = xmNickInclude.Fields;
            }
            else
            {
                change = 0;
                ScriptManager.RegisterStartupScript(this.grdvClients, this.Page.GetType(), "BindGrid", "ChangeOverflow('" + change + "')", true);//ajax
                grdvClients.DataSource = "";
                grdvClients.DataBind();
                base.ShowMessage("请先设置项目的预算字段!");
                return;
            }
            List <HozestERP.BusinessLogic.ManageBusiness.XMProjectCostDetail> List = new List <HozestERP.BusinessLogic.ManageBusiness.XMProjectCostDetail>();

            string[] parm = includefields.Split(',');
            string   pID  = "";           //父节点ID
            string   cID  = "";           //子节点ID

            if (parm != null && parm.Count() > 0)
            {
                foreach (string id in parm)
                {
                    var f = base.XMFinancialFieldService.GetXMFinancialFieldById(int.Parse(id));
                    if (f != null)
                    {
                        if (f.ParentID == 0)
                        {
                            pID += f.Id + ",";
                        }
                        else
                        {
                            cID += f.Id + ",";
                        }
                    }
                }
            }
            if (pID != "" && pID.Length > 0)
            {
                pID = pID.Substring(0, pID.Length - 1);
            }
            if (cID != "" && cID.Length > 0)
            {
                cID = cID.Substring(0, cID.Length - 1);
            }
            string[] p = pID.Split(',');
            string[] c = cID.Split(',');

            if (p != null && p.Length > 0)
            {
                for (int j = 0; j < p.Count(); j++)
                {
                    if (no == 1)
                    {
                        str.Append("<table   style='height: 5px;width:100%;border-style:solid' rules='all'>");
                        str.Append("<tr  style='font-weight:bold;height:30px;background-color:#EEEEEE'>");
                        str.Append("<th  nowrap='noWrap' align='center' style='width:120px;white-space:nowrap;cursor:pointer;' scope='col'>项目</th>");
                        str.Append("<th  nowrap='noWrap' align='center' style='width:60px;white-space:nowrap;cursor:pointer;' scope='col'>1-12月累计</th>");
                        str.Append("<th  nowrap='noWrap' align='center' style='width:70px;white-space:nowrap;cursor:pointer;' scope='col'>占毛利比</th>");

                        str.Append("</tr>");
                    }
                    str.Append("<tr class='GridRow' align='center' style='background-color:#EAEAEA;height:5px;height:5px;' oldcolor=#EAEAEA'>");
                    str.Append("<td style='width:120px;font-size:18px;'>" + getFieldNameByFieldID(p[j]) + "</td>");
                    str.Append("<td style='width:60px;text-align:center'>" + getSumAllCost(p[j]) + "</td>");
                    if (YYYJCost != 0)
                    {
                        str.Append("<td style='width:70px;text-align:center'>" + Math.Round(getSumAllCost(p[j]) / YYYJCost, 2) * 100 + "%" + "</td>");
                    }
                    else
                    {
                        str.Append("<td style='width:70px;text-align:center'>" + 0 + "%" + "</td>");
                    }
                    str.Append("</tr>");
                    HozestERP.BusinessLogic.ManageBusiness.XMProjectCostDetail pCost = null;
                    if (this.ProjectId != 0)
                    {
                        pCost = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(p[j]), ProjectId, int.Parse(ddlYear.SelectedValue));
                    }
                    if (this.NickID != 0)
                    {
                        pCost = XMProjectCostDetailService.GetXMProjectCostDataByNick(int.Parse(p[j]), NickID, int.Parse(ddlYear.SelectedValue));
                    }
                    //var pCost = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(p[j]), ProjectId, int.Parse(ddlYear.SelectedValue));
                    if (pCost != null && pCost.FieldName != "")
                    {
                        List.Add(pCost);
                    }
                    //字段管理中该字段已经删除,应清理该条数据
                    if (pCost != null && pCost.FieldName == "")
                    {
                        pCost.IsEnable   = true;
                        pCost.UpdateDate = DateTime.Now;
                        pCost.UpdateID   = HozestERPContext.Current.User.CustomerID;
                        base.XMProjectCostDetailService.UpdateXMProjectCostDetail(pCost);
                    }
                    if (HasChild(p[j]))
                    {
                        string newStr = childFieldIDs(p[j]);
                        if (!string.IsNullOrEmpty(newStr))
                        {
                            foreach (string childID in c)
                            {
                                foreach (string str1 in newStr.Split(','))
                                {
                                    if (childID == str1)               //存在该子节点
                                    {
                                        str.Append("<tr class='GridRow' align='center' style='background-color:#FFFFFF;height:5px;height:5px;' oldcolor=#FFFFFF'>");
                                        str.Append("<td style='width:120px;text-align:right'>" + getFieldNameByFieldID(childID) + "</td>");
                                        str.Append("<td style='width:60px;text-align:center'>" + getSumAllCost(childID) + "</td>");
                                        if (YYYJCost != 0)
                                        {
                                            str.Append("<td style='width:70px;text-align:center'>" + Math.Round(getSumAllCost(childID) / YYYJCost, 2) * 100 + "%" + "</td>");
                                        }
                                        else
                                        {
                                            str.Append("<td style='width:70px;text-align:center'>" + 0 + "%" + "</td>");
                                        }
                                        HozestERP.BusinessLogic.ManageBusiness.XMProjectCostDetail childCost = null;
                                        if (this.ProjectId != 0)
                                        {
                                            childCost = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(p[j]), ProjectId, int.Parse(ddlYear.SelectedValue));
                                        }
                                        if (this.NickID != 0)
                                        {
                                            childCost = XMProjectCostDetailService.GetXMProjectCostDataByNick(int.Parse(p[j]), NickID, int.Parse(ddlYear.SelectedValue));
                                        }
                                        //var childCost = base.XMProjectCostDetailService.GetXMProjectCostDataByParm(int.Parse(childID), ProjectId, int.Parse(ddlYear.SelectedValue));
                                        if (childCost != null && childCost.FieldName != "")
                                        {
                                            List.Add(childCost);
                                        }
                                        if (childCost != null && childCost.FieldName == "")
                                        {
                                            childCost.IsEnable   = true;
                                            childCost.UpdateDate = DateTime.Now;
                                            childCost.UpdateID   = HozestERPContext.Current.User.CustomerID;
                                            base.XMProjectCostDetailService.UpdateXMProjectCostDetail(childCost);
                                        }
                                        //字段管理中该字段已经删除,应该删除该条数据
                                        if (childCost != null && childCost.FieldName == "")
                                        {
                                            childCost.IsEnable   = true;
                                            childCost.UpdateDate = DateTime.Now;
                                            childCost.UpdateID   = HozestERPContext.Current.User.CustomerID;
                                            base.XMProjectCostDetailService.UpdateXMProjectCostDetail(childCost);
                                        }
                                    }
                                }
                            }
                            str.Append("</tr>");
                        }
                    }
                    no++;
                }
                if (List.Count > 0)
                {
                    change = 1;
                    str.Append("<tr class='GridRow' style='background-color:#F7F7F7'><td style='height:10px;' colspan='9'></td></tr></table>");
                    TableStr = str.ToString();
                }
                ScriptManager.RegisterStartupScript(this.grdvClients, this.Page.GetType(), "BindGrid", "ChangeOverflow('" + change + "')", true);//ajax
                grdvClients.DataSource = List;
                grdvClients.DataBind();
            }
        }