Example #1
0
        /// <summary>
        /// 运行工作记录簿
        /// </summary>
        /// <param name="yxgzjl">工作记录</param>
        /// <param name="nrList">工作记录内容</param>
        public static void ExportExcelYxgzjlb(bdjl_yxgzjlb yxgzjl, IList<bdjl_gzjlzb> nrList)
        {
            #region  运行工作记录簿        
            ExcelAccess ex = new ExcelAccess();
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string fname = Application.StartupPath + "\\00记录模板\\运行工作记录簿.xls";
            ex.Open(fname);
            int row = 1;
            int rowmaxsize = 117;//一行最多33个汉字
            //加页
            int pageindex = 1;
            int totalHang = GetTotalHang(nrList, rowmaxsize);
            if (pageindex < Ecommonjh.GetPagecount(totalHang, 12))
            {
                pageindex = Ecommonjh.GetPagecount(totalHang, 12);
            }
            

            for (int j = 1; j <= pageindex; j++)
            {
                ex.ActiveSheet(1);
                
                if (j > 1)
                {
                    ex.CopySheet(1, 1);
                }
                
            }
            ex.ActiveSheet(1);
            ex.SetCellValue(Convert.ToDateTime(yxgzjl.rq).Year + "年" + Convert.ToDateTime(yxgzjl.rq).Month + "月"
                    + Convert.ToDateTime(yxgzjl.rq).Day + "日", 2, 1);
            ex.SetCellValue("星期:"+GetWeeks(Convert.ToDateTime(yxgzjl.rq).DayOfWeek), 2, 4);
            ex.SetCellValue("天气:"+yxgzjl.tq, 2, 7);
            ex.SetCellValue(yxgzjl.jbfzr, 3, 3);
            ex.SetCellValue(yxgzjl.jbry, 3, 7);
            ex.SetCellValue(yxgzjl.jbfzry, 4, 3);
            ex.SetCellValue(yxgzjl.jbryy, 4, 7);
            int kyh = 0;//空余行
            int r = 0;//列表循环
            int temp = 0;
            for (int j = 1; j <= pageindex; j++)
            {
                ex.ActiveSheet(j);
                //ex.ReNameWorkSheet(j, "Sheet" + (j));
                int prepageindex = j - 1;
                //主题
                int starow = prepageindex * 12 + 1;
                int endrow = j * 12;
                
                if (totalHang > endrow)
                {
                    for (int i = 0; i < 12; )
                    {
                        int hasrow = GetHasRow(nrList[r].nr.Length, rowmaxsize);
                        if (temp == 0)
                        {
                            ex.SetCellValue(Convert.ToDateTime(nrList[r].sj).Hour.ToString(), row + 5 + i, 1);
                            ex.SetCellValue(Convert.ToDateTime(nrList[r].sj).Minute.ToString(), row + 5 + i, 2);
                        }
                        for (int t = 1; t <= hasrow; t++)
                        {
                            if (temp > 0)
                            {
                                t = temp;
                                temp = 0;
                            }
                            string tempnr = "";
                            if (t != hasrow)
                            {
                                tempnr = nrList[r].nr.Substring((t - 1) * rowmaxsize, t * rowmaxsize - ((t - 1) * rowmaxsize));
                            }
                            else
                            {
                                tempnr = nrList[r].nr.Substring((t - 1) * rowmaxsize, nrList[r].nr.Length - ((t - 1) * rowmaxsize));
                            }
                            ex.SetCellValue(tempnr, row + 5 + i, 3);
                            i++;
                            if (i > 12)
                            {
                                temp = t;
                                break;
                            }
                        }

                        //ex.SetCellValue(nrList[starow - 1 + i].jlr, row + 4 + i, 13);
                        if (temp == 0)
                            r++;
                    }
                }
                else if (totalHang <= endrow && totalHang >= starow)
                {
                    for (int i = 0; i < totalHang - starow + 1+kyh; )
                    {
                        if (temp == 0)
                        {
                            ex.SetCellValue(Convert.ToDateTime(nrList[r].sj).Hour.ToString(), row + 5 + i, 1);
                            ex.SetCellValue(Convert.ToDateTime(nrList[r].sj).Minute.ToString(), row + 5 + i, 2);
                        }
                        int hasrow = GetHasRow(nrList[r].nr.Length, rowmaxsize);
                        for (int t = 1; t <= hasrow; t++)
                        {
                            if (temp > 0)
                            {
                                t = temp;
                                temp = 0;
                            }
                            string tempnr = "";
                            if (t != hasrow)
                            {
                                tempnr = nrList[r].nr.Substring((t - 1) * rowmaxsize, t * rowmaxsize - ((t - 1) * rowmaxsize));
                            }
                            else
                            {
                                tempnr = nrList[r].nr.Substring((t - 1) * rowmaxsize, nrList[r].nr.Length - ((t - 1) * rowmaxsize));
                            }
                            ex.SetCellValue(tempnr, row + 5 + i, 3);
                            i++;
                        }

                        //ex.SetCellValue(nrList[starow - 1 + i].jlr, row + 4 + i, 13);
                        r++;
                    }
                }

            }
            ex.ActiveSheet(1);
            ex.ShowExcel();
            #endregion
        }
Example #2
0
 private void btAdds_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (string.IsNullOrEmpty(parentID))
     {
         MsgBox.ShowWarningMessageBox("请先选择一个变电所!");
         return;
     }
     frm_yxgzjlb frm = new frm_yxgzjlb();
     bdjl_yxgzjlb yxgzjlb = new bdjl_yxgzjlb();
     yxgzjlb.OrgCode = parentID;
     yxgzjlb.rq = DateTime.Now.ToShortDateString();
     frm.RowData = yxgzjlb;
     if (frm.ShowDialog() == DialogResult.OK)
     {
         Client.ClientHelper.PlatformSqlMap.Create<bdjl_yxgzjlb>(frm.RowData);
         RefreshGridData("");
     }
 }