Exemplo n.º 1
0
        public void downM()
        {
            try
            {
                var direc = HttpContext.Current.Server.MapPath(HttpPostedFileExtension.POSTED_FILE_ROOT_DIRECTORY);
                //@"D:\member\wanghuanjun\Ipms\Solution\0.3\Ipms.WebSite\IpmsDocument\
                var templateName = direc + "专项管理书模板.doc";
                var savePath = direc + "专项管理书.doc";

                WordCOMHelper wordTemplate = new WordCOMHelper(templateName, savePath);
                Dictionary<WordTableCell, string> wordCellContent = new Dictionary<WordTableCell, string>();
                //Microsoft.Office.Interop.Word.Table wordTable1 = wordTemplate.Document.Tables[1];
                //Microsoft.Office.Interop.Word.Table wordTable2 = wordTemplate.Document.Tables[2];
                //Microsoft.Office.Interop.Word.Table wordTable3 = wordTemplate.Document.Tables[3];
                //Microsoft.Office.Interop.Word.Table wordTable4 = wordTemplate.Document.Tables[4];
                //Microsoft.Office.Interop.Word.Table wordTable5 = wordTemplate.Document.Tables[5];

                var Mid = Request.GetInt("MItemID");

                var project = Database.Projects.SingleOrDefault(cti => cti.ID == Mid);
                var projectContentForum = Database.ProjectContentForums.SingleOrDefault(pct => pct.ProjectContentType.Project == project && pct.ProjectContentType.ContentTypeID == 4 && pct.ContentForum.ContentTypeID == 4 && pct.ContentForum.ForumID == 1);
                var labExchange = Database.LaboratoryExchanges.SingleOrDefault(d => d.ProjectContentForumID == projectContentForum.ID);
                var labaccount = Database.LabAccounts.SingleOrDefault(la => la.CollegeID == labExchange.LabID);
                var college = Database.Colleges.SingleOrDefault(c => c.ID == labExchange.LabID);
                var tasks = Database.LaboratoryExchangeTasks.Where(let => let.LaboratoryExchangeID == labExchange.ID).ToList();
                //首页内容
                wordTemplate.Document.Bookmarks.get_Item("ProjectName").Range.Text = project.ProjectName;
                wordTemplate.Document.Bookmarks.get_Item("ManagerName").Range.Text = project.Manager.Name;
                wordTemplate.Document.Bookmarks.get_Item("College").Range.Text = college.Name;
                wordTemplate.Document.Bookmarks.get_Item("Phone").Range.Text = project.Contactor.MobilePhone;
                wordTemplate.Document.Bookmarks.get_Item("Total").Range.Text = (labExchange.Amount / 10000).ToString();
                wordTemplate.Document.Bookmarks.get_Item("Year").Range.Text = labExchange.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Year1").Range.Text = labExchange.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Year2").Range.Text = labExchange.Year.ToString();
                ////第1个表格内容
                wordTemplate.Document.Bookmarks.get_Item("ProjectName1").Range.Text = project.ProjectName;
                wordTemplate.Document.Bookmarks.get_Item("Object").Range.Text = project.Object;
                string text = "1." + tasks[0].Content ;
                for (int i = 1; i < tasks.Count(); i++)
                {
                    text = text + ";" + "\r" + (i + 1) + "." + tasks[i].Content;

                }
                wordTemplate.Document.Bookmarks.get_Item("Text").Range.Text = text;
                ////第2个表格内容
                wordTemplate.SetCurrentTable(2);

                int rowNum = 3;
                foreach (var temp in tasks)
                {
                    WordTableCell num = new WordTableCell(rowNum, 1);
                    wordCellContent[num] = (rowNum - 2).ToString();

                    DateTime bt = Convert.ToDateTime(temp.BeginTime);
                    int btm = bt.Month;
                    DateTime et = Convert.ToDateTime(temp.EndTime);
                    int etm = et.Month;

                    WordTableCell time = new WordTableCell(rowNum, 2);
                    if(btm == etm)
                    {
                        wordCellContent[time] = btm.ToString() + "月";
                    }
                    else
                    wordCellContent[time] = btm + "-" + etm + "月";

                    WordTableCell mamager = new WordTableCell(rowNum, 3);
                    wordCellContent[mamager] = project.Manager.Name;

                    WordTableCell content = new WordTableCell(rowNum, 4);
                    wordCellContent[content] = temp.Content;

                    var details = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID);
                    double amount = 0;
                    foreach(var tem in details)
                    {

                        amount = amount + Convert.ToDouble(tem.Amount);
                    }
                    //var aaa = amount;
                    WordTableCell amount1 = new WordTableCell(rowNum, 5);
                    wordCellContent[amount1] = amount / 10000 + "万元";

                    wordTemplate.AddRow();
                    rowNum++;
                }

                ////第3个表格内容
                wordTemplate.Document.Bookmarks.get_Item("Total1").Range.Text = (labExchange.Amount / 10000).ToString();
                wordTemplate.Document.Bookmarks.get_Item("Accounting").Range.Text = labaccount.Account;
                ////第4个表格内容
                //办公费
                double officecost = 0;
                var officecostex = "";
                foreach (var temp in tasks)
                {
                    var officeamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 1).ToList();

                    foreach (var tem in officeamount)
                    {
                        officecost = officecost + Convert.ToDouble(tem.Amount);
                        officecostex = officecostex + " " + tem.Detail;
                    }

                }
                if (officecost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Officecost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Officecost").Range.Text = Convert.ToString(officecost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Officecostex").Range.Text = officecostex;
                //打印费
                double printcost = 0;
                var printcostex = "";
                foreach (var temp in tasks)
                {
                    var printamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 2).ToList();

                    foreach (var tem in printamount)
                    {
                        printcost = printcost + Convert.ToDouble(tem.Amount);
                        printcostex = printcostex + " " + tem.Detail;
                    }

                }
                if (printcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Printcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Printcost").Range.Text = Convert.ToString(printcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Printcostex").Range.Text = printcostex;
                //邮寄费
                double mailcost = 0;
                var mailcostex = "";
                foreach (var temp in tasks)
                {
                    var mailamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 3).ToList();

                    foreach (var tem in mailamount)
                    {
                        mailcost = mailcost + Convert.ToDouble(tem.Amount);
                        mailcostex = mailcostex + " " + tem.Detail;
                    }

                }
                if (mailcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Mailcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Mailcost").Range.Text = Convert.ToString(mailcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Mailcostex").Range.Text = mailcostex;
                //交通fei
                double trcost = 0;
                var trcostex = "";
                foreach (var temp in tasks)
                {
                    var tramount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 4).ToList();

                    foreach (var tem in tramount)
                    {
                        trcost = trcost + Convert.ToDouble(tem.Amount);
                        trcostex = trcostex + " " + tem.Detail;
                    }

                }
                if (trcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Trcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Trcost").Range.Text = Convert.ToString(trcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Trcostex").Range.Text = trcostex;
                //会议费
                double meetingcost = 0;
                var meetingcostex = "";
                foreach (var temp in tasks)
                {
                    var meetingamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 5).ToList();

                    foreach (var tem in meetingamount)
                    {
                        meetingcost = meetingcost + Convert.ToDouble(tem.Amount);
                        meetingcostex = meetingcostex + " " + tem.Detail;
                    }

                }
                if (meetingcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Meetingcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Meetingcost").Range.Text = Convert.ToString(meetingcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Meetingcostex").Range.Text = meetingcostex;
                //差旅费内
                double intocost = 0;
                var intocostex = "";
                foreach (var temp in tasks)
                {
                    var intoamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 6).ToList();

                    foreach (var tem in intoamount)
                    {
                        intocost = intocost + Convert.ToDouble(tem.Amount);
                        intocostex = intocostex + " " + tem.Detail;
                    }

                }
                if (intocost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Intocost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Intocost").Range.Text = Convert.ToString(intocost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Intocost").Range.Text = intocostex;
                //其他内
                double inothercost = 0;
                var inothercostex = "";
                foreach (var temp in tasks)
                {
                    var inotheramount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 7).ToList();

                    foreach (var tem in inotheramount)
                    {
                        inothercost = inothercost + Convert.ToDouble(tem.Amount);
                        inothercostex = inothercostex + " " + tem.Detail;
                    }

                }
                if (inothercost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Inothercost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Inothercost").Range.Text = Convert.ToString(inothercost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Inothercostex").Range.Text = inothercostex;
                //差旅费 外
                double outtocost = 0;
                var outtocostex = "";
                foreach (var temp in tasks)
                {
                    var outtoamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 8).ToList();

                    foreach (var tem in outtoamount)
                    {
                        outtocost = outtocost + Convert.ToDouble(tem.Amount);
                        outtocostex = outtocostex + " " + tem.Detail;
                    }

                }
                if (outtocost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Outtocost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Outtocost").Range.Text = Convert.ToString(outtocost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Outtocostex").Range.Text = outtocostex;
                //通讯网络费
                double netcost = 0;
                var netcostex = "";
                foreach (var temp in tasks)
                {
                    var netamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 10).ToList();

                    foreach (var tem in netamount)
                    {
                        netcost = netcost + Convert.ToDouble(tem.Amount);
                        netcostex = netcostex + " " + tem.Detail;
                    }

                }
                if (netcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Netcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Netcost").Range.Text = Convert.ToString(netcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Netcostex").Range.Text = netcostex;
                //专家咨询劳务费
                double consultcost = 0;
                var consultcostex = "";
                foreach (var temp in tasks)
                {
                    var consultamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 11).ToList();

                    foreach (var tem in consultamount)
                    {
                        consultcost = consultcost + Convert.ToDouble(tem.Amount);
                        consultcostex = consultcostex + " " + tem.Detail;
                    }

                }
                if (consultcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Consultcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Consultcost").Range.Text = Convert.ToString(consultcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Consultcostex").Range.Text = consultcostex;
                //出版 文献
                double publishcost = 0;
                var publishcostex = "";
                foreach (var temp in tasks)
                {
                    var publishamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 12).ToList();

                    foreach (var tem in publishamount)
                    {
                        publishcost = publishcost + Convert.ToDouble(tem.Amount);
                        publishcostex = publishcostex + " " + tem.Detail;
                    }

                }
                if (publishcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Publishcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Publishcost").Range.Text = Convert.ToString(publishcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Publishcostex").Range.Text = publishcostex;
                //维修
                double maintaincost = 0;
                var maintaincostex = "";
                foreach (var temp in tasks)
                {
                    var maintainamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 13).ToList();

                    foreach (var tem in maintainamount)
                    {
                        maintaincost = maintaincost + Convert.ToDouble(tem.Amount);
                        maintaincostex = maintaincostex + " " + tem.Detail;
                    }

                }
                if (maintaincost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Maintaincost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Maintaincost").Range.Text = Convert.ToString(maintaincost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Maintaincostex").Range.Text = maintaincostex;
                //培训
                double traincost = 0;
                var traincostex = "";
                foreach (var temp in tasks)
                {
                    var trainamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 14).ToList();

                    foreach (var tem in trainamount)
                    {
                        traincost = traincost + Convert.ToDouble(tem.Amount);
                        traincostex = traincostex + " " + tem.Detail;
                    }

                }
                if (traincost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Traincost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Traincost").Range.Text = Convert.ToString(traincost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Traincostex").Range.Text = traincostex;
                //办公设备购置
                double officedevicecost = 0;
                var officedevicecostex = "";
                foreach (var temp in tasks)
                {
                    var officedeviceamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 15).ToList();

                    foreach (var tem in officedeviceamount)
                    {
                        officedevicecost = officedevicecost + Convert.ToDouble(tem.Amount);
                        officedevicecostex = officedevicecostex + " " + tem.Detail;
                    }

                }
                if (officedevicecost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Officedevicecost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Officedevicecost").Range.Text = Convert.ToString(officedevicecost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Officedevicecostex").Range.Text = officedevicecostex;
                //专用设备购置
                double spdevicecost = 0;
                var spdevicecostex = "";
                foreach (var temp in tasks)
                {
                    var spdeviceamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 16).ToList();

                    foreach (var tem in spdeviceamount)
                    {
                        spdevicecost = spdevicecost + Convert.ToDouble(tem.Amount);
                        spdevicecostex = spdevicecostex + " " + tem.Detail;
                    }

                }
                if (spdevicecost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Spdevicecost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Spdevicecost").Range.Text = Convert.ToString(spdevicecost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Spdevicecostex").Range.Text = spdevicecostex;
                //专用材料购置
                double spmacost = 0;
                var spmacostex = "";
                foreach (var temp in tasks)
                {
                    var spmaamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 17).ToList();

                    foreach (var tem in spmaamount)
                    {
                        spmacost = spmacost + Convert.ToDouble(tem.Amount);
                        spmacostex = spmacostex + " " + tem.Detail;
                    }

                }
                if (spmacost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Spmacost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Spmacost").Range.Text = Convert.ToString(spmacost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Spmacostex").Range.Text = spmacostex;
                //委托加工业务
                double entrustcost = 0;
                var entrustcostex = "";
                foreach (var temp in tasks)
                {
                    var entrustamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 18).ToList();

                    foreach (var tem in entrustamount)
                    {
                        entrustcost = entrustcost + Convert.ToDouble(tem.Amount);
                        entrustcostex = entrustcostex + " " + tem.Detail;
                    }

                }
                if (entrustcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Entrustcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Entrustcost").Range.Text = Convert.ToString(entrustcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Entrustcostex").Range.Text = entrustcostex;
                //人员及劳务费
                double workcost = 0;
                var workcostex = "";
                foreach (var temp in tasks)
                {
                    var workamount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 19).ToList();

                    foreach (var tem in workamount)
                    {
                        workcost = workcost + Convert.ToDouble(tem.Amount);
                        workcostex = workcostex + " " + tem.Detail;
                    }

                }
                if (workcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Workcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Workcost").Range.Text = Convert.ToString(workcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Workcostex").Range.Text = workcostex;
                //其他费用 外
                double outothercost = 0;
                var outothercostex = "";
                foreach (var temp in tasks)
                {
                    var outotheramount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 20).ToList();

                    foreach (var tem in outotheramount)
                    {
                        outothercost = outothercost + Convert.ToDouble(tem.Amount);
                        outothercostex = outothercostex + " " + tem.Detail;
                    }

                }
                if (outothercost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Outothercost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Outothercost").Range.Text = Convert.ToString(outothercost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Outothercostex").Range.Text = outothercostex;
                //专用材料购置1
                double spma1cost = 0;
                var spma1costex = "";
                foreach (var temp in tasks)
                {
                    var spma1amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 22).ToList();

                    foreach (var tem in spma1amount)
                    {
                        spma1cost = spma1cost + Convert.ToDouble(tem.Amount);
                        spma1costex = spma1costex + " " + tem.Detail;
                    }

                }
                if (spma1cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Spma1cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Spma1cost").Range.Text = Convert.ToString(spma1cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Spma1costex").Range.Text = spma1costex;
                //委托加工业务1
                double entrust1cost = 0;
                var entrust1costex = "";
                foreach (var temp in tasks)
                {
                    var entrust1amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 23).ToList();

                    foreach (var tem in entrust1amount)
                    {
                        entrust1cost = entrust1cost + Convert.ToDouble(tem.Amount);
                        entrust1costex = entrust1costex + " " + tem.Detail;
                    }

                }
                if (entrust1cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Entrust1cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Entrust1cost").Range.Text = Convert.ToString(entrust1cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Entrust1costex").Range.Text = entrust1costex;
                //差旅费1
                double outto1cost = 0;
                var outto1costex = "";
                foreach (var temp in tasks)
                {
                    var outto1amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 24).ToList();

                    foreach (var tem in outto1amount)
                    {
                        outto1cost = outto1cost + Convert.ToDouble(tem.Amount);
                        outto1costex = outto1costex + " " + tem.Detail;
                    }

                }
                if (outto1cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Outto1cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Outto1cost").Range.Text = Convert.ToString(outto1cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Outto1costex").Range.Text = outto1costex;
                //高级访问学者经费
                double scholarcost = 0;
                var scholarcostex = "";
                foreach (var temp in tasks)
                {
                    var scholaramount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 25).ToList();

                    foreach (var tem in scholaramount)
                    {
                        scholarcost = scholarcost + Convert.ToDouble(tem.Amount);
                        scholarcostex = scholarcostex + " " + tem.Detail;
                    }

                }
                if (scholarcost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Scholarcost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Scholarcost").Range.Text = Convert.ToString(scholarcost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Scholarcostex").Range.Text = scholarcostex;
                //人员及劳务费1
                double work1cost = 0;
                var work1costex = "";
                foreach (var temp in tasks)
                {
                    var work1amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 26).ToList();

                    foreach (var tem in work1amount)
                    {
                        work1cost = work1cost + Convert.ToDouble(tem.Amount);
                        work1costex = work1costex + " " + tem.Detail;
                    }

                }
                if (work1cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Work1cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Work1cost").Range.Text = Convert.ToString(work1cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Work1costex").Range.Text = work1costex;
                //差旅住宿2
                double outto2cost = 0;
                var outto2costex = "";
                foreach (var temp in tasks)
                {
                    var outto2amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 27).ToList();

                    foreach (var tem in outto2amount)
                    {
                        outto2cost = outto2cost + Convert.ToDouble(tem.Amount);
                        outto2costex = outto2costex + " " + tem.Detail;
                    }

                }
                if (outto2cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Outto2cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Outto2cost").Range.Text = Convert.ToString(outto2cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Outto2costex").Range.Text = outto2costex;
                //其他内1
                double inother1cost = 0;
                var inother1costex = "";
                foreach (var temp in tasks)
                {
                    var inother1amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 28).ToList();

                    foreach (var tem in inother1amount)
                    {
                        inother1cost = inother1cost + Convert.ToDouble(tem.Amount);
                        inother1costex = inother1costex + " " + tem.Detail;
                    }

                }
                if (inother1cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Inother1cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Inother1cost").Range.Text = Convert.ToString(inother1cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Inother1costex").Range.Text = inother1costex;

                //其他费用 外
                double outother1cost = 0;
                var outother1costex = "";
                foreach (var temp in tasks)
                {
                    var outother1amount = Database.LaboratoryExchangeTaskDetails.Where(letd => letd.LaboratoryExchangeTaskID == temp.ID && letd.AccountingSubjectID == 29).ToList();

                    foreach (var tem in outother1amount)
                    {
                        outother1cost = outother1cost + Convert.ToDouble(tem.Amount);
                        outother1costex = outother1costex + " " + tem.Detail;
                    }

                }
                if (outother1cost == 0)
                {
                    wordTemplate.Document.Bookmarks.get_Item("Outother1cost").Range.Text = "";
                }
                else
                wordTemplate.Document.Bookmarks.get_Item("Outother1cost").Range.Text = Convert.ToString(outother1cost / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Outother1costex").Range.Text = outother1costex;

                double dailyamount = officecost + printcost + mailcost + trcost + meetingcost + outtocost + netcost + publishcost + maintaincost + traincost + officedevicecost + spdevicecost + spmacost + entrustcost + workcost + outothercost + intocost + inothercost + consultcost;
                double openamount = spma1cost + entrust1cost + outto1cost + scholarcost + outother1cost + work1cost + outto2cost + inother1cost;
                double totalamount = dailyamount + openamount;

                wordTemplate.Document.Bookmarks.get_Item("Dailyamount").Range.Text = Convert.ToString(dailyamount / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Openamount").Range.Text = Convert.ToString(openamount / 10000);
                wordTemplate.Document.Bookmarks.get_Item("Totalamount").Range.Text = Convert.ToString(totalamount / 10000);

                wordTemplate.FillTableContent(wordCellContent);
                wordTemplate.Save();

                downLoad(direc + "专项管理书.doc", "专项管理书.doc");
            }
            catch (System.Exception ex)
            {
                new PackedException("专项管理书模板", ex).Hanldle();
            }
        }
Exemplo n.º 2
0
        public void downBudget()
        {
            try
            {
                var direc = HttpContext.Current.Server.MapPath(HttpPostedFileExtension.POSTED_FILE_ROOT_DIRECTORY);
                //@"D:\member\wanghuanjun\Ipms\Solution\0.3\Ipms.WebSite\IpmsDocument\
                var Bid = Request.GetInt("budgetID");
                var templateName = direc + "经费下达文件模板.doc";
                var savePath = direc + "经费下达文件.doc";

                WordCOMHelper wordTemplate = new WordCOMHelper(templateName, savePath);
                Dictionary<WordTableCell, string> wordCellContent = new Dictionary<WordTableCell, string>();
                Microsoft.Office.Interop.Word.Table wordTable1 = wordTemplate.Document.Tables[1];
                Microsoft.Office.Interop.Word.Table wordTable2 = wordTemplate.Document.Tables[2];

                var construcktask = Database.ConstructTasks.SingleOrDefault(ct =>ct.ID == Bid);
                var construcktaskitems = Database.ConstructTaskItems.Where(cti =>cti.ConstructTaskID == Bid).GroupBy(cti =>cti.ConstructPlanItem.ConstructPlanPackage.PackageNumber);

                wordTemplate.Document.Bookmarks.get_Item("DocNumber").Range.Text = construcktask.DocNumber;
                wordTemplate.Document.Bookmarks.get_Item("DocName").Range.Text = construcktask.DocName;
                wordTemplate.Document.Bookmarks.get_Item("DocRemark").Range.Text = construcktask.Remark;
                wordTemplate.Document.Bookmarks.get_Item("Year1").Range.Text = construcktask.ReportYear;
                wordTemplate.Document.Bookmarks.get_Item("Year2").Range.Text = construcktask.ReportYear;
                wordTemplate.Document.Bookmarks.get_Item("Year3").Range.Text = construcktask.ReportYear;
                wordTemplate.Document.Bookmarks.get_Item("Year4").Range.Text = construcktask.ReportYear;
                wordTemplate.Document.Bookmarks.get_Item("DocSource").Range.Text = construcktask.FundSource.ToString();

                wordTemplate.SetCurrentTable(2);
                int rowNum = 2;
                int number = 2;
                int plus = 0;
                double totalapply = 0;
                double totalcontrol = 0;
                foreach (var group in construcktaskitems)
                {
                    int a = group.Count();
                    string groupfield = "";
                    double control = 0;
                    string college = "";
                    foreach (var temp in group)
                    {

                        WordTableCell deviceNumber = new WordTableCell(rowNum, 1);
                        wordCellContent[deviceNumber] = temp.ConstructPlanItem.DeviceNumber;

                        WordTableCell deviceName = new WordTableCell(rowNum, 4);
                        wordCellContent[deviceName] = temp.ConstructPlanItem.MemberApplyItem.ApplyDevice.DeviceName;

                        var marketDevice = Database.DeviceMatchs.SingleOrDefault(dm => dm.ApplyDeviceID == temp.ConstructPlanItem.MemberApplyItem.ApplyDeviceID && dm.MarketDevice.IsRecommended == true).MarketDevice;

                        WordTableCell manufactures = new WordTableCell(rowNum, 5);
                        wordCellContent[manufactures] = marketDevice.Manufactures;

                        WordTableCell deviceType = new WordTableCell(rowNum, 6);
                        wordCellContent[deviceType] = temp.ConstructPlanItem.MemberApplyItem.ApplyDevice.DeviceType;

                        WordTableCell quantity = new WordTableCell(rowNum, 7);
                        wordCellContent[quantity] = temp.Quantity.ToString();

                        WordTableCell unitPrice = new WordTableCell(rowNum, 8);
                        wordCellContent[unitPrice] = (Convert.ToDouble(temp.ConstructPlanItem.MemberApplyItem.ApplyDevice.UnitPrice) / 1000000).ToString();

                        WordTableCell amount = new WordTableCell(rowNum, 9);
                        wordCellContent[amount] = (Convert.ToDouble(temp.ConstructPlanItem.MemberApplyItem.ApplyDevice.UnitPrice * temp.Quantity) / 1000000).ToString();

                        //WordTableCell college = new WordTableCell(rowNum, 10);
                        //wordCellContent[college] = temp.ConstructPlanItem.ConstructPlanPackage.Project.College.Name;

                        WordTableCell name1 = new WordTableCell(rowNum, 11);
                        wordCellContent[name1] = temp.ConstructPlanItem.MemberApplyItem.ApplicantName;

                        WordTableCell phoneNumber1 = new WordTableCell(rowNum, 12);
                        wordCellContent[phoneNumber1] = temp.ConstructPlanItem.MemberApplyItem.PhoneNumber;

                        WordTableCell name2 = new WordTableCell(rowNum, 13);
                        wordCellContent[name2] = temp.ConstructPlanItem.MemberApplyItem.ApplicantName;

                        WordTableCell phoneNumber2 = new WordTableCell(rowNum, 14);
                        wordCellContent[phoneNumber2] = temp.ConstructPlanItem.MemberApplyItem.PhoneNumber;

                        groupfield = temp.ConstructPlanItem.ConstructPlanPackage.PackageNumber;
                        control = temp.ConstructPlanItem.ConstructPlanPackage.ControllerAmount.Value / 1000000;
                        college = temp.ConstructPlanItem.ConstructPlanPackage.Project.College.Name;

                        totalapply = totalapply + Convert.ToDouble(temp.ConstructPlanItem.MemberApplyItem.ApplyDevice.UnitPrice * temp.Quantity) / 1000000;

                        wordTemplate.AddRow();
                        rowNum++;
                    }
                    if (a > 1)
                    {
                        wordTable2.Cell(number + plus, 2).Merge(wordTable2.Cell(number + plus + a - 1, 2));
                        wordTable2.Cell(number + plus, 3).Merge(wordTable2.Cell(number + plus + a - 1, 3));
                        wordTable2.Cell(number + plus, 10).Merge(wordTable2.Cell(number + plus + a - 1, 10));

                    }

                    WordTableCell groupField = new WordTableCell(number + plus, 2);
                    wordCellContent[groupField] = groupfield;

                    WordTableCell controllerAmount = new WordTableCell(number + plus, 3);
                    wordCellContent[controllerAmount] = control.ToString();

                    WordTableCell college1 = new WordTableCell(number + plus, 10);
                    wordCellContent[college1] = college;

                    plus = plus + a;
                    totalcontrol = totalcontrol + control;
                }
                wordTemplate.DeleteRow(rowNum);

                wordTemplate.Document.Bookmarks.get_Item("ApplyAmount").Range.Text = totalapply.ToString();
                wordTemplate.Document.Bookmarks.get_Item("ControlAmount").Range.Text = totalcontrol.ToString();

                wordTemplate.FillTableContent(wordCellContent);
                wordTemplate.Save();

                downLoad(direc + "经费下达文件.doc", "经费下达文件.doc");
            }
            catch (System.Exception ex)
            {
                new PackedException("经费下达文件模板", ex).Hanldle();
            }
        }
Exemplo n.º 3
0
        public void downCheck()
        {
            try
            {
                var direc = HttpContext.Current.Server.MapPath(HttpPostedFileExtension.POSTED_FILE_ROOT_DIRECTORY);
                //@"D:\member\wanghuanjun\Ipms\Solution\0.3\Ipms.WebSite\IpmsDocument\
                var templateName = direc + "预算核定表模板.doc";
                var savePath = direc + "预算核定表.doc";

                WordCOMHelper wordTemplate = new WordCOMHelper(templateName, savePath);
                Dictionary<WordTableCell, string> wordCellContent = new Dictionary<WordTableCell, string>();
                var Cid = Request.GetInt("checkItemID");
                var financeBudgetCheck = Database.FinanceBudgetChecks.SingleOrDefault(cti => cti.ID == Cid);
                wordTemplate.Document.Bookmarks.get_Item("Time").Range.Text = Convert.ToDateTime(financeBudgetCheck.CheckDate).ToShortDateString();
                var financeBudgetCheckItem = Database.FinanceBudgetCheckItems.Where(fbci => fbci.FinanceBudgetCheckID == Cid );

                int rowNum = 3;
                long rmb = 0;
                double usd = 0;
                double euro = 0;
                double jpy = 0;
                double cad = 0;
                double asd = 0;
                double hkd = 0;
                double gbp = 0;
                double alloAmount = 0;

                foreach (var item in financeBudgetCheckItem)
                {
                    WordTableCell num = new WordTableCell(rowNum, 1);
                    wordCellContent[num] = (rowNum - 2).ToString();

                    WordTableCell contractNumber = new WordTableCell(rowNum, 2);
                    wordCellContent[contractNumber] = item.AssetFundApplyItem.ContractItem.Contract.Number;

                    WordTableCell supplierName = new WordTableCell(rowNum, 3);
                    wordCellContent[supplierName] = item.AssetFundApplyItem.ContractItem.Contract.Supplier.Name;

                    WordTableCell rmbAmount = new WordTableCell(rowNum, 4);
                    WordTableCell usdAmount = new WordTableCell(rowNum, 5);
                    WordTableCell euroAmount = new WordTableCell(rowNum, 6);
                    WordTableCell jpyAmount = new WordTableCell(rowNum, 7);
                    WordTableCell cadAmount = new WordTableCell(rowNum, 8);
                    WordTableCell asdAmount = new WordTableCell(rowNum, 9);
                    WordTableCell hkdAmount = new WordTableCell(rowNum, 10);
                    WordTableCell gbpAmount = new WordTableCell(rowNum, 11);
                    if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 0)
                    {
                        wordCellContent[rmbAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        rmb = rmb + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }
                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 1)
                    {
                        wordCellContent[usdAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        usd = usd + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }

                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 2)
                    {
                        wordCellContent[euroAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        euro = euro + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }
                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 3)
                    {
                        wordCellContent[jpyAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        jpy = jpy + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }

                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 4)
                    {
                        wordCellContent[cadAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        cad = cad + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }

                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 5)
                    {
                        wordCellContent[asdAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        asd = asd + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }

                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 6)
                    {
                        wordCellContent[hkdAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        hkd = hkd + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }

                    else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 7)
                    {
                        wordCellContent[gbpAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString();
                        gbp = gbp + (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100);
                    }

                    WordTableCell platName = new WordTableCell(rowNum, 12);
                    wordCellContent[platName] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.MemberApply.College.PlatForm.PlatName;

                    WordTableCell account = new WordTableCell(rowNum, 13);
                    if (Convert.ToString(item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructTask.Account) == "StateAssetOffice")
                    wordCellContent[account] = "国资处预算账号";
                    else
                        wordCellContent[account] = "学院相应账号";

                    WordTableCell departmentCode = new WordTableCell(rowNum, 14);
                    wordCellContent[departmentCode] = item.FinanceBudgetCheck.Department.Code;

                    WordTableCell projectCode = new WordTableCell(rowNum, 15);
                    wordCellContent[projectCode] = item.ProjectCode;

                    WordTableCell allocateAmount = new WordTableCell(rowNum, 16);
                    wordCellContent[allocateAmount] = item.AllocateAmount.ToString();
                    alloAmount = alloAmount + Convert.ToDouble(item.AllocateAmount);
                    wordTemplate.AddRow();
                    rowNum++;
                }
                WordTableCell totalSum = new WordTableCell(rowNum, 1);
                wordCellContent[totalSum] = "合计";

                WordTableCell rmbSum = new WordTableCell(rowNum, 4);
                if(rmb == 0)
                    wordCellContent[rmbSum] = "";
                else
                wordCellContent[rmbSum] = rmb.ToString();

                WordTableCell usdSum = new WordTableCell(rowNum, 5);
                if(usd == 0)
                    wordCellContent[usdSum] = "";
                else
                wordCellContent[usdSum] = usd.ToString();

                WordTableCell euroSum = new WordTableCell(rowNum, 6);
                if (euro == 0)
                    wordCellContent[euroSum] = "";
                else
                wordCellContent[euroSum] = euro.ToString();

                WordTableCell jpySum = new WordTableCell(rowNum, 7);
                if (jpy == 0)
                    wordCellContent[jpySum] = "";
                else
                wordCellContent[jpySum] = jpy.ToString();

                WordTableCell cadSum = new WordTableCell(rowNum, 8);
                if (cad == 0)
                    wordCellContent[cadSum] = "";
                else
                wordCellContent[cadSum] = cad.ToString();

                WordTableCell asdSum = new WordTableCell(rowNum, 9);
                if (asd == 0)
                    wordCellContent[asdSum] = "";
                else
                wordCellContent[asdSum] = asd.ToString();

                WordTableCell hkdSum = new WordTableCell(rowNum, 10);
                if (hkd == 0)
                    wordCellContent[hkdSum] = "";
                else
                wordCellContent[hkdSum] = hkd.ToString();

                WordTableCell gbpSum = new WordTableCell(rowNum, 11);
                if (gbp == 0)
                    wordCellContent[gbpSum] = "";
                else
                wordCellContent[gbpSum] = gbp.ToString();

                WordTableCell alloAmount1 = new WordTableCell(rowNum, 16);
                wordCellContent[alloAmount1] = alloAmount.ToString();

                wordTemplate.FillTableContent(wordCellContent);

                wordTemplate.Save();

                downLoad(direc + "预算核定表.doc", "预算核定表.doc");
            }
            catch (System.Exception ex)
            {
                new PackedException("经费预算明细表", ex).Hanldle();
            }
        }
Exemplo n.º 4
0
        public void downDetail()
        {
            try
            {
                var direc = HttpContext.Current.Server.MapPath(HttpPostedFileExtension.POSTED_FILE_ROOT_DIRECTORY);
                //@"D:\member\wanghuanjun\Ipms\Solution\0.3\Ipms.WebSite\IpmsDocument\
                var templateName = direc + "经费预算明细表模板.doc";
                var savePath = direc + "经费预算明细表.doc";

                WordCOMHelper wordTemplate = new WordCOMHelper(templateName, savePath);
                Dictionary<WordTableCell, string> wordCellContent = new Dictionary<WordTableCell, string>();
                var Did = Request.GetInt("detailItemID");
                var OfficeBudgetDetail = Database.OfficeBudgetDetails.SingleOrDefault(cti => cti.ID == Did);
                wordTemplate.Document.Bookmarks.get_Item("DocOfficeBugdetNumber").Range.Text = OfficeBudgetDetail.DetailNumber;
                //对平台项目进行查询小计
                var OfficeBudgetDetailItemPT = Database.OfficeBudgetDetailItems.Where(ctii => ctii.OfficeBudgetDetailID == Did && ctii.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.ConstructPlanPackage.PlatFormID != null).GroupBy(ctii => ctii.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.ConstructPlanPackage.Project.College.Name);
                //double applyTotalAmountSumPTTotal = 0;
                double budgetAmountSumPTTotal = 0;
                double officeAmountSumPTTotal = 0;
                int rowNum = 2;
                int count = 0;
                foreach (var group in OfficeBudgetDetailItemPT)
                {
                    //double applyTotalAmountSumPT = 0;
                    double budgetAmountSumPT = 0;
                    double officeAmountSumPT = 0;
                    foreach (var item in group)
                    {

                        WordTableCell num = new WordTableCell(rowNum, 1);
                        wordCellContent[num] = (rowNum - 1 - count).ToString();

                        WordTableCell contractNumber = new WordTableCell(rowNum, 2);
                        wordCellContent[contractNumber] = item.AssetFundApplyItem.ContractItem.Contract.Number;

                        WordTableCell supplierName = new WordTableCell(rowNum, 3);
                        wordCellContent[supplierName] = item.AssetFundApplyItem.ContractItem.Contract.Supplier.Name;

                        WordTableCell budgetAmount = new WordTableCell(rowNum, 4);
                        wordCellContent[budgetAmount] = (item.AssetFundApplyItem.ContractItem.Quantity * item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.ApplyDevice.UnitPrice / 100).ToString();

                        WordTableCell contractItemAmount = new WordTableCell(rowNum, 5);
                        if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 0)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "¥";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 1)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 2)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "€";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 3)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "JPY";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 4)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "C$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 5)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "A$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 6)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "HK$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 7)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "£";

                        //WordTableCell applyTotalAmount = new WordTableCell(rowNum, 6);
                        //wordCellContent[applyTotalAmount] = (item.AssetFundApplyItem.ApplyTotalAmount / 100).ToString();

                        WordTableCell officeIssuedAmount = new WordTableCell(rowNum, 6);
                        wordCellContent[officeIssuedAmount] = (item.OfficeIssuedAmount/ 100).ToString();

                        WordTableCell uSDRate = new WordTableCell(rowNum, 7);
                        wordCellContent[uSDRate] = item.AssetFundApplyItem.ContractItem.BidResultItem.USDRate.ToString();

                        WordTableCell tradeAgentFeeRate = new WordTableCell(rowNum, 8);
                        wordCellContent[tradeAgentFeeRate] = item.AssetFundApplyItem.ContractItem.BidResultItem.TradeAgentFeeRate.ToString();

                        WordTableCell productName = new WordTableCell(rowNum, 9);
                        wordCellContent[productName] = item.AssetFundApplyItem.ContractItem.ProductName;

                        WordTableCell bcQuantity = new WordTableCell(rowNum, 10);
                        wordCellContent[bcQuantity] = item.AssetFundApplyItem.ContractItem.Quantity.ToString();

                        WordTableCell collegeName = new WordTableCell(rowNum, 11);
                        wordCellContent[collegeName] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.MemberApply.College.Name;

                        WordTableCell expertName = new WordTableCell(rowNum, 12);
                        wordCellContent[expertName] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.MemberApply.Member.Name;

                        WordTableCell deviceNumber = new WordTableCell(rowNum, 13);
                        wordCellContent[deviceNumber] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.DeviceNumber;

                        WordTableCell remark1 = new WordTableCell(rowNum, 14);
                        wordCellContent[remark1] = item.Remark1;

                        WordTableCell remark2 = new WordTableCell(rowNum, 15);
                        wordCellContent[remark2] = item.Remark2;
                        wordTemplate.AddRow();

                        //applyTotalAmountSumPT = applyTotalAmountSumPT + Convert.ToDouble(item.AssetFundApplyItem.ApplyTotalAmount / 100);
                        budgetAmountSumPT = budgetAmountSumPT + Convert.ToDouble((item.AssetFundApplyItem.ContractItem.Quantity * item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.ApplyDevice.UnitPrice / 100));
                        officeAmountSumPT = officeAmountSumPT + Convert.ToDouble(item.OfficeIssuedAmount / 100);
                        //applyTotalAmountSumPTTotal = applyTotalAmountSumPTTotal + Convert.ToDouble(item.AssetFundApplyItem.ApplyTotalAmount / 100);
                        budgetAmountSumPTTotal = budgetAmountSumPTTotal + Convert.ToDouble((item.AssetFundApplyItem.ContractItem.Quantity * item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.ApplyDevice.UnitPrice / 100));
                        officeAmountSumPTTotal = officeAmountSumPTTotal + Convert.ToDouble(item.OfficeIssuedAmount / 100);
                        rowNum++;
                    }
                    WordTableCell namePT = new WordTableCell(rowNum, 1);
                    wordCellContent[namePT] = "小计";
                    count++;

                    WordTableCell budgetAmountSumPT1 = new WordTableCell(rowNum, 4);
                    wordCellContent[budgetAmountSumPT1] = budgetAmountSumPT.ToString();

                    //WordTableCell applyTotalAmountSum1 = new WordTableCell(rowNum, 6);
                    //wordCellContent[applyTotalAmountSum1] = applyTotalAmountSumPT.ToString();

                    WordTableCell officeAmountSumPT1 = new WordTableCell(rowNum, 6);
                    wordCellContent[officeAmountSumPT1] = officeAmountSumPT.ToString();

                    WordTableCell ratio = new WordTableCell(rowNum, 14);
                    var ratio1 = string.Format("{0:P2}", officeAmountSumPT / budgetAmountSumPT);
                    wordCellContent[ratio] = ratio1.ToString();

                    WordTableCell typePT = new WordTableCell(rowNum, 15);
                    wordCellContent[typePT] = "平台";

                    wordTemplate.AddRow();
                    rowNum++;
                }
                //对人才项目进行查询小计
                var OfficeBudgetDetailItemRC = Database.OfficeBudgetDetailItems.Where(ctii => ctii.OfficeBudgetDetailID == Did && ctii.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.ConstructPlanPackage.OutStandingID != null).GroupBy(ctii => ctii.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.Applicant.Name);
                //double applyTotalAmountSumRCTotal = 0;
                double budgetAmountSumRCTotal = 0;
                double officeAmountSumRCTotal = 0;
                foreach (var group in OfficeBudgetDetailItemRC)
                {
                    //double applyTotalAmountSumRC = 0;
                    double budgetAmountSumRC = 0;
                    double officeAmountSumRC = 0;
                    foreach (var item in group)
                    {

                        WordTableCell num = new WordTableCell(rowNum, 1);
                        wordCellContent[num] = (rowNum - 1 - count).ToString();

                        WordTableCell contractNumber = new WordTableCell(rowNum, 2);
                        wordCellContent[contractNumber] = item.AssetFundApplyItem.ContractItem.Contract.Number;

                        WordTableCell supplierName = new WordTableCell(rowNum, 3);
                        wordCellContent[supplierName] = item.AssetFundApplyItem.ContractItem.Contract.Supplier.Name;

                        WordTableCell budgetAmount = new WordTableCell(rowNum, 4);
                        wordCellContent[budgetAmount] = (item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.BudgetAmount / 100).ToString();

                        WordTableCell contractItemAmount = new WordTableCell(rowNum, 5);
                        if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 0)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "¥";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 1)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 2)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "€";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 3)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "JPY";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 4)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "C$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 5)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "A$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 6)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "HK$";
                        else if (Convert.ToInt32(item.AssetFundApplyItem.ContractItem.BidResultItem.Currency) == 7)
                            wordCellContent[contractItemAmount] = (item.AssetFundApplyItem.ContractItem.ContractItemAmount / 100).ToString() + "£";

                        //WordTableCell applyTotalAmount = new WordTableCell(rowNum, 6);
                        //wordCellContent[applyTotalAmount] = (item.AssetFundApplyItem.ApplyTotalAmount / 100).ToString();

                        WordTableCell officeIssuedAmount = new WordTableCell(rowNum, 6);
                        wordCellContent[officeIssuedAmount] = (item.OfficeIssuedAmount / 100).ToString();

                        WordTableCell uSDRate = new WordTableCell(rowNum, 7);
                        wordCellContent[uSDRate] = item.AssetFundApplyItem.ContractItem.BidResultItem.USDRate.ToString();

                        WordTableCell tradeAgentFeeRate = new WordTableCell(rowNum, 8);
                        wordCellContent[tradeAgentFeeRate] = item.AssetFundApplyItem.ContractItem.BidResultItem.TradeAgentFeeRate.ToString();

                        WordTableCell productName = new WordTableCell(rowNum, 9);
                        wordCellContent[productName] = item.AssetFundApplyItem.ContractItem.ProductName;

                        WordTableCell bcQuantity = new WordTableCell(rowNum, 10);
                        wordCellContent[bcQuantity] = item.AssetFundApplyItem.ContractItem.Quantity.ToString();

                        WordTableCell collegeName = new WordTableCell(rowNum, 11);
                        wordCellContent[collegeName] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.MemberApply.College.Name;

                        WordTableCell expertName = new WordTableCell(rowNum, 12);
                        wordCellContent[expertName] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.MemberApplyItem.MemberApply.Member.Name;

                        WordTableCell deviceNumber = new WordTableCell(rowNum, 13);
                        wordCellContent[deviceNumber] = item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.DeviceNumber;

                        WordTableCell remark1 = new WordTableCell(rowNum, 14);
                        wordCellContent[remark1] = item.Remark1;

                        WordTableCell remark2 = new WordTableCell(rowNum, 15);
                        wordCellContent[remark2] = item.Remark2;
                        wordTemplate.AddRow();

                        //applyTotalAmountSumRC = applyTotalAmountSumRC + Convert.ToDouble(item.AssetFundApplyItem.ApplyTotalAmount / 100);
                        budgetAmountSumRC = budgetAmountSumRC + Convert.ToDouble(item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.BudgetAmount / 100);
                        officeAmountSumRC = officeAmountSumRC + Convert.ToDouble(item.OfficeIssuedAmount / 100);
                        //applyTotalAmountSumRCTotal = applyTotalAmountSumRCTotal + Convert.ToDouble(item.AssetFundApplyItem.ApplyTotalAmount / 100);
                        budgetAmountSumRCTotal = budgetAmountSumRCTotal + Convert.ToDouble(item.AssetFundApplyItem.ContractItem.BidResultItem.PurchaseOrderItem.PurchasePlanItem.ConstructTaskItem.ConstructPlanItem.BudgetAmount / 100);
                        officeAmountSumRCTotal = officeAmountSumRCTotal + Convert.ToDouble(item.OfficeIssuedAmount / 100);
                        rowNum++;
                    }
                    WordTableCell nameRC = new WordTableCell(rowNum, 1);
                    wordCellContent[nameRC] = "小计";
                    count++;

                    WordTableCell budgetAmountSumRC1 = new WordTableCell(rowNum, 4);
                    wordCellContent[budgetAmountSumRC1] = budgetAmountSumRC.ToString();

                    //WordTableCell applyTotalAmountSumRC1 = new WordTableCell(rowNum, 6);
                    //wordCellContent[applyTotalAmountSumRC1] = applyTotalAmountSumRC.ToString();

                    WordTableCell officeAmountSumRC1 = new WordTableCell(rowNum, 6);
                    wordCellContent[officeAmountSumRC1] = officeAmountSumRC.ToString();

                    WordTableCell ratio = new WordTableCell(rowNum, 14);
                    var ratio1 = string.Format("{0:P2}", officeAmountSumRC / budgetAmountSumRC);
                    wordCellContent[ratio] = ratio1.ToString();

                    WordTableCell typeRC = new WordTableCell(rowNum, 15);
                    wordCellContent[typeRC] = "人才";

                    wordTemplate.AddRow();
                    rowNum++;
                }

                var budgetAmountSumTotal = budgetAmountSumRCTotal + budgetAmountSumPTTotal;
                //var applyTotalAmountSumTotal = applyTotalAmountSumRCTotal + applyTotalAmountSumPTTotal;
                var officeAmountSumTotal = officeAmountSumRCTotal + officeAmountSumPTTotal;
                WordTableCell totalSum = new WordTableCell(rowNum, 1);
                wordCellContent[totalSum] = "合计";

                //WordTableCell two = new WordTableCell(rowNum, 2);
                //WordTableCell three = new WordTableCell(rowNum, 3);
                //wordTemplate.MergeCell(two, three);

                WordTableCell budgetAmountSumTotal1 = new WordTableCell(rowNum, 4);
                wordCellContent[budgetAmountSumTotal1] = budgetAmountSumTotal.ToString();

                //WordTableCell applyTotalAmountSumTotal1 = new WordTableCell(rowNum, 6);
                //wordCellContent[applyTotalAmountSumTotal1] = applyTotalAmountSumTotal.ToString();

                WordTableCell officeAmountSumTotal1 = new WordTableCell(rowNum, 6);
                wordCellContent[officeAmountSumTotal1] = officeAmountSumTotal.ToString();

                WordTableCell ratioTotal = new WordTableCell(rowNum, 14);
                var ratioTotal1 = string.Format("{0:P2}", officeAmountSumTotal / budgetAmountSumTotal);
                wordCellContent[ratioTotal] = ratioTotal1.ToString();

                wordTemplate.FillTableContent(wordCellContent);
                wordTemplate.Save();

                //SaveDocument(wordDocument, wordApp, direc + "经费预算明细表.doc");

                downLoad(direc + "经费预算明细表.doc", "经费预算明细表.doc");

                var downLoadInfo = string.Format("{0}下载设备:{1},经费预算明细表", User.Name, OfficeBudgetDetail.Operator);
                BusinessLog.Write(User, Request.UserHostAddress, downLoadInfo, Database);
            }
            catch (System.Exception ex)
            {
                new PackedException("经费预算明细表", ex).Hanldle();
            }
        }
Exemplo n.º 5
0
        public void downTemplate()
        {
            try
            {
                var direc = HttpContext.Current.Server.MapPath(HttpPostedFileExtension.POSTED_FILE_ROOT_DIRECTORY);
                //@"D:\member\wanghuanjun\Ipms\Solution\0.3\Ipms.WebSite\IpmsDocument\
                var templateName = direc + "申报书模板.doc";
                var savePath = direc + "申报书.doc";

                WordCOMHelper wordTemplate = new WordCOMHelper(templateName, savePath);

                Microsoft.Office.Interop.Word.Table wordTable1 = wordTemplate.Document.Tables[1];
                Microsoft.Office.Interop.Word.Table wordTable2 = wordTemplate.Document.Tables[2];
                Microsoft.Office.Interop.Word.Table wordTable3 = wordTemplate.Document.Tables[3];
                Microsoft.Office.Interop.Word.Table wordTable4 = wordTemplate.Document.Tables[4];
                Microsoft.Office.Interop.Word.Table wordTable5 = wordTemplate.Document.Tables[5];

                var Iid = Request.GetInt("tastItemID");

                var project = Database.Projects.SingleOrDefault(cti => cti.ID == Iid);

                //第一个表格内容
                wordTemplate.Document.Bookmarks.get_Item("ProjectName").Range.Text = project.ProjectName;
                wordTemplate.Document.Bookmarks.get_Item("ProjectManager").Range.Text = project.Manager.Name;
                wordTemplate.Document.Bookmarks.get_Item("ProjectCompany").Range.Text = project.College.Name;
                wordTemplate.Document.Bookmarks.get_Item("Year").Range.Text = DateTime.Now.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Tyear1").Range.Text = DateTime.Now.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Tyear2").Range.Text = DateTime.Now.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Tyear3").Range.Text = DateTime.Now.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Tyear5").Range.Text = DateTime.Now.Year.ToString();
                wordTemplate.Document.Bookmarks.get_Item("Nyear1").Range.Text = (Convert.ToInt32(DateTime.Now.Year) + 1).ToString();
                wordTemplate.Document.Bookmarks.get_Item("Nyear2").Range.Text = (Convert.ToInt32(DateTime.Now.Year) + 1).ToString();
                wordTemplate.Document.Bookmarks.get_Item("Nyear3").Range.Text = (Convert.ToInt32(DateTime.Now.Year) + 1).ToString();
                wordTemplate.Document.Bookmarks.get_Item("Nyear4").Range.Text = (Convert.ToInt32(DateTime.Now.Year) + 1).ToString();
                wordTemplate.Document.Bookmarks.get_Item("Nyear5").Range.Text = (Convert.ToInt32(DateTime.Now.Year) + 1).ToString();
                wordTemplate.Document.Bookmarks.get_Item("month").Range.Text = DateTime.Now.Month.ToString();
                wordTemplate.Document.Bookmarks.get_Item("day").Range.Text = DateTime.Now.Day.ToString();
                //第二个表格内容
                var Contactor = Database.Experts.SingleOrDefault(ex => ex.ID == project.ContactorID);
                wordTable2.Cell(2, 2).Range.Text = project.College.PlatForm.PlatName;
                wordTable2.Cell(5, 2).Range.Text = project.College.Name;
                wordTable2.Cell(6, 2).Range.Text = project.Manager.Name;
                wordTable2.Cell(7, 2).Range.Text = Contactor.Name;
                wordTable2.Cell(7, 4).Range.Text = Contactor.MobilePhone;

                var projectMembers = Database.ProjectMembers.Where(pm => pm.ProjectID == Iid).ToList();
                for (int i = 0; i < projectMembers.Count(); i++)
                {
                    var expert = Database.Experts.SingleOrDefault(ex => ex.UserID == projectMembers[i].MemberID);
                    wordTable2.Cell(10 + i, 1).Range.Text = expert.Name;
                    wordTable2.Cell(10 + i, 2).Range.Text = expert.Post;
                    wordTable2.Cell(10 + i, 3).Range.Text = expert.AcademyDegree;
                    wordTable2.Cell(10 + i, 5).Range.Text = expert.College.Name;
                    if (expert.College2ID == null) {
                        wordTable2.Cell(10 + i, 6).Range.Text = "全职";
                    }
                    else
                    wordTable2.Cell(10 + i, 6).Range.Text = "双聘";
                }
                //第三个表格内容 建设目标
                wordTemplate.Document.Bookmarks.get_Item("Object").Range.Text = project.Object;

                //第四个表格内容 建设内容
                var systemcontent = Database.SystemConstructions.Where(sc => sc.ProjectID == project.ID).ToList();
                var teamcontent = Database.TeamConstructions.Where(sc => sc.ProjectID == project.ID).ToList();
                if (systemcontent.Count() != 0 && teamcontent.Count!= 0)
                    wordTemplate.Document.Bookmarks.get_Item("Content").Range.Text = systemcontent[0].Description + ";" + "\r" + teamcontent[0].Description;
                else if (systemcontent.Count != 0)
                    wordTemplate.Document.Bookmarks.get_Item("Content").Range.Text = systemcontent[0].Description;
                else if (teamcontent.Count != 0)
                    wordTemplate.Document.Bookmarks.get_Item("Content").Range.Text = teamcontent[0].Description;
                else
                    wordTemplate.Document.Bookmarks.get_Item("Content").Range.Text = "暂无";

                //第五个表格内容 建设成效
                wordTemplate.Document.Bookmarks.get_Item("Achieve").Range.Text = project.Achievement;

                //第六个表格内容 清单
                var memberApplyItems = Database.MemberApplyItems.Where(mai => mai.MemberApply.ProjectID == Iid && mai.CurrentState != MemberApplyState.ManagerDeny ).ToList();
                wordTemplate.SetCurrentTable(6);
                int textNum = 1;
                string text = "";
                int rowNum = 2;
                int quantitySum = 0;
                double amountSum = 0;
                Dictionary<WordTableCell, string> wordCellContent = new Dictionary<WordTableCell, string>();
                foreach (var temp in memberApplyItems)
                {
                    var marketDevice = Database.DeviceMatchs.SingleOrDefault(dm => dm.ApplyDeviceID == temp.ApplyDeviceID && dm.MarketDevice.IsRecommended == true).MarketDevice;
                    WordTableCell num = new WordTableCell(rowNum, 1);
                    wordCellContent[num] = (rowNum - 1).ToString();

                    WordTableCell deviceName = new WordTableCell(rowNum, 2);
                    wordCellContent[deviceName] = temp.ApplyDevice.DeviceName;

                    WordTableCell manufactures = new WordTableCell(rowNum, 3);
                    wordCellContent[manufactures] = marketDevice.Manufactures;

                    WordTableCell deviceType = new WordTableCell(rowNum, 4);
                    wordCellContent[deviceType] = temp.ApplyDevice.DeviceType;

                    WordTableCell configuration = new WordTableCell(rowNum, 5);
                    wordCellContent[configuration] = temp.ApplyDevice.Configuration;

                    WordTableCell unitPrice = new WordTableCell(rowNum, 6);

                    wordCellContent[unitPrice] = (Convert.ToDouble(temp.ApplyDevice.UnitPrice) / 1000000).ToString();

                    WordTableCell quantity = new WordTableCell(rowNum, 7);
                    wordCellContent[quantity] = temp.Quantity.ToString();

                    WordTableCell amount = new WordTableCell(rowNum, 8);
                    wordCellContent[amount] = (Convert.ToDouble(temp.ApplyDevice.UnitPrice * temp.Quantity) / 1000000).ToString();

                    WordTableCell name = new WordTableCell(rowNum, 9);
                    wordCellContent[name] = temp.ApplicantName;

                    WordTableCell phoneNumber = new WordTableCell(rowNum, 10);
                    wordCellContent[phoneNumber] = temp.PhoneNumber;

                    string text1;
                    var others = Database.DeviceExtramurals.Where(de => de.ApplyDeviceID == temp.ApplyDeviceID).ToList();
                    if (others.Count != 0)
                        text1 = others[0].WorkUnit + "于" + Convert.ToDateTime(others[0].BuyTime).ToShortDateString() + "以购置价格" + (Convert.ToDouble(others[0].UnitPrice) / 1000000) + "万元" + "购买了品牌为" + others[0].Brand + "的" + others[0].ApplyDevice.DeviceName;
                    else
                        text1 = "暂无";
                    text = text + textNum + "." + temp.ApplyDevice.DeviceName + "\r" + "[" + "必要性分析:" + temp.ApplyDevice.NecessityAnalysis + "]" + "\r" + "[" + "主要研究方向:" + temp.ApplyDevice.ResearchDirections + "]" + "\r" + "[" + "预期效益分析:" + temp.ApplyDevice.BenefitExpect + "]" + "\r" + "[" + "合理性比较:" + temp.ApplyDevice.ReasonableComparison + "]" + "\r" + "[" + "校外购置状况:" + text1 + "]" + "\r";
                    quantitySum = quantitySum + Convert.ToInt32(temp.Quantity);
                    amountSum = amountSum + Convert.ToDouble(temp.ApplyDevice.UnitPrice * temp.Quantity) / 1000000;

                    wordTemplate.AddRow();
                    rowNum++;
                    textNum++;
                }

                WordTableCell sum = new WordTableCell(rowNum, 1);
                wordCellContent[sum] = "合计";

                WordTableCell quantitySum1 = new WordTableCell(rowNum, 7);
                wordCellContent[quantitySum1] = quantitySum.ToString();

                WordTableCell amountSum1 = new WordTableCell(rowNum, 8);
                wordCellContent[amountSum1] = amountSum.ToString();

                wordTemplate.FillTableContent(wordCellContent);

                wordTemplate.Document.Bookmarks.get_Item("Details").Range.Text = text;
                wordTemplate.Save();

                downLoad(direc + "申报书.doc", "申报书.doc");
            }
            catch (System.Exception ex)
            {
                new PackedException("申报书模板", ex).Hanldle();
            }
        }