private void ChangeLaunchButtonText(DataGrid dgrid, string text, bool isEnable, int selectedIndex)
 {
     if (dgrid.Dispatcher.CheckAccess())
     {
         var cp = (ContentPresenter)dgrid.GetCell(selectedIndex, 5).Content;
         TextBlock tbLaunchName = (TextBlock)cp.ContentTemplate.FindName("tbLaunchName", cp);
         tbLaunchName.IsEnabled = isEnable;
         tbLaunchName.Text = text;
     }
     else
     {
         dgrid.Dispatcher.Invoke(
             new Action<DataGrid, string, bool, int>((c, s, i, d)
             => ChangeLaunchButtonText(dgrid, text, isEnable, selectedIndex)),
             new object[] { dgrid, text, isEnable, selectedIndex });
     }
 }
 private void ChangeRPLaunchButtonText(DataGrid dgrid, string text, bool isEnable, int selectedIndex)
 {
     var cp = (ContentPresenter)dgrid.GetCell(selectedIndex, 3).Content;
     TextBlock tbLaunchName = (TextBlock)cp.ContentTemplate.FindName("tbLaunchName", cp);
     tbLaunchName.IsEnabled = isEnable;
     tbLaunchName.Text = text;
 }
 private void UpdateProcessID(DataGrid dgrid, Process process, int lcid, bool isDebugConsole, int selectedIndex)
 {
     if (dgrid.Dispatcher.CheckAccess())
     {
         int pid = process.Id;
         TextBlock tb = new TextBlock();
         tb.Text = pid.ToString();
         dgrid.GetCell(selectedIndex, 4).Content = tb;
         listLanguages.FirstOrDefault(lng => lng.UniversalID == lcid).PID = pid.ToString();
         UpdateProcessInRegistry(process, lcid, isDebugConsole);
     }
     else
     {
         dgrid.Dispatcher.Invoke(
             new Action<DataGrid, Process, int, bool, int>((c, p, l, i, d)
             => UpdateProcessID(dgrid, process, lcid, isDebugConsole, selectedIndex)),
             new object[] { dgrid, process, lcid, isDebugConsole, selectedIndex });
     }
 }
 private void UpdateRPProcessID(DataGrid dgrid, Process process, int lcid, int selectedIndex)
 {
     int pid = process.Id;
     var cp = (ContentPresenter)dgrid.GetCell(selectedIndex, 3).Content;
     TextBlock tbLaunchName = (TextBlock)cp.ContentTemplate.FindName("tbLaunchName", cp);
     tbLaunchName.Tag = pid;
     listRPLanguages.FirstOrDefault(lng => lng.UniversalID == lcid).PID = pid.ToString();
     Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\Reporting\\" + pid.ToString(), "LCID", lcid, RegistryValueKind.String);
     Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\Reporting\\" + pid.ToString(), "SessionID", process.SessionId.ToString(), RegistryValueKind.String);
     Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\Reporting\\" + pid.ToString(), "UserName", WindowsIdentity.GetCurrent().Name, RegistryValueKind.String);
 }
        private void UpdateCPProcessID(DataGrid dgrid, Process process, int lcid, int selectedIndex, string appletTitle)
        {
            int pid = process.Id;
            var cp = (ContentPresenter)dgrid.GetCell(selectedIndex, 3).Content;
            TextBlock tbLaunchName = (TextBlock)cp.ContentTemplate.FindName("tbLaunchName", cp);
            tbLaunchName.Tag = pid;
            listCPLanguages.FirstOrDefault(lng => lng.UniversalID == lcid).PID = pid.ToString();
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\ControlPanelApplet\\" + process.Id.ToString(), "AppletTitle", appletTitle, RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\ControlPanelApplet\\" + process.Id.ToString(), "LCID", lcid, RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\ControlPanelApplet\\" + process.Id.ToString(), "SessionID", process.SessionId.ToString(), RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\ControlPanelApplet\\" + process.Id.ToString(), "UserName", WindowsIdentity.GetCurrent().Name, RegistryValueKind.String);

            if (!dictCurrentCPInfo.ContainsKey(pid))
            {
                CPAppletInfo info = new CPAppletInfo();
                info.LCID = lcid;
                info.ProcessID = pid;
                info.SessionID = process.SessionId;
                info.UserName = WindowsIdentity.GetCurrent().Name;
                info.AppletTitle = appletTitle;
                dictCurrentCPInfo.Add(pid, info);
            }
        }
 private void ChangeSCLaunchButtonText(DataGrid dgrid, string text, bool isEnable, int selectedIndex, bool isNewVersion)
 {
     int columnIndex = isNewVersion ? 3 : 4;
     string tbLaunchNameStr = isNewVersion ? "tbLaunchNewVersionName" : "tbLaunchOldVersionName";
     var cp = (ContentPresenter)dgrid.GetCell(selectedIndex, columnIndex).Content;
     TextBlock tbLaunchName = (TextBlock)cp.ContentTemplate.FindName(tbLaunchNameStr, cp);
     tbLaunchName.IsEnabled = isEnable;
     tbLaunchName.Text = text;
 }
        private void UpdateSCProcessID(DataGrid dgrid, Process process, int lcid, bool isDebugConsole, int selectedIndex, bool isNewVersion)
        {
            int pid = process.Id;
            int columnIndex = isNewVersion ? 3 : 4;
            string tbLaunchNameStr = isNewVersion ? "tbLaunchNewVersionName" : "tbLaunchOldVersionName";
            var cp = (ContentPresenter)dgrid.GetCell(selectedIndex, columnIndex).Content;
            TextBlock tbLaunchName = (TextBlock)cp.ContentTemplate.FindName(tbLaunchNameStr, cp);
            tbLaunchName.Tag = pid;
            if (isNewVersion)
            {
                listClientLanguages.FirstOrDefault(lng => lng.UniversalID == lcid).PIDNewVersion = pid.ToString();
            }
            else
            {
                listClientLanguages.FirstOrDefault(lng => lng.UniversalID == lcid).PIDOldVersion = pid.ToString();
            }
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\SoftwareCenter\\" + process.Id.ToString(), "LCID", lcid, RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\SoftwareCenter\\" + process.Id.ToString(), "IsDebugConsole", isDebugConsole, RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\SoftwareCenter\\" + process.Id.ToString(), "SessionID", process.SessionId.ToString(), RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\SoftwareCenter\\" + process.Id.ToString(), "UserName", WindowsIdentity.GetCurrent().Name, RegistryValueKind.String);
            Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + Settings.RegistrySettingName + "\\SoftwareCenter\\" + process.Id.ToString(), "IsNewVersion", isNewVersion, RegistryValueKind.String);

            if (!dictCurrentSCInfo.ContainsKey(pid))
            {
                SoftwareCenterInfo info = new SoftwareCenterInfo();
                info.IsDebugConsole = isDebugConsole;
                info.IsNewVersion = isNewVersion;
                info.LCID = lcid;
                info.ProcessID = pid;
                info.SessionID = process.SessionId;
                info.UserName = WindowsIdentity.GetCurrent().Name;
                dictCurrentSCInfo.Add(pid, info);
            }
        }
示例#8
0
        public static void EE(DataGrid dg, string Title, string date = "")
        {
            int rowCount    = dg.Items.Count;           //行数
            int columnCount = dg.Columns.Count;         //列数

            HSSFWorkbook workbook = new HSSFWorkbook(); //创建workbook对象
            HSSFSheet    sheet    = (HSSFSheet)workbook.CreateSheet();

            sheet.DefaultColumnWidth = 15;//设置默认的宽度

            //定义title的font和cell样式
            HSSFFont      fontTitle  = SheetStyle.GetFont(workbook, 24, FontBoldWeight.BOLD);
            HSSFCellStyle styleTitle = SheetStyle.GetStyle(workbook);

            styleTitle.SetFont(fontTitle);

            //定义date的font和cell样式
            HSSFFont      fontDate  = SheetStyle.GetFont(workbook, 12);
            HSSFCellStyle styleDate = SheetStyle.GetStyle(workbook);

            styleDate.SetFont(fontDate);

            //定义header的font和cell样式
            HSSFFont      fontHeader    = SheetStyle.GetFont(workbook, 12, FontBoldWeight.BOLD);
            HSSFCellStyle styleHeaderLT = SheetStyle.GetStyle(workbook, CellPosition.LeftTop);//左上

            styleHeaderLT.SetFont(fontHeader);
            HSSFCellStyle styleHeaderRT = SheetStyle.GetStyle(workbook, CellPosition.RightTop);//右上

            styleHeaderRT.SetFont(fontHeader);
            HSSFCellStyle styleHeaderT = SheetStyle.GetStyle(workbook, CellPosition.Top);//上

            styleHeaderT.SetFont(fontHeader);

            //定义content的font和cell样式
            HSSFFont      fontContent   = SheetStyle.GetFont(workbook, 12);
            HSSFCellStyle styleContentL = SheetStyle.GetStyle(workbook, CellPosition.Left);//左

            styleContentL.SetFont(fontContent);
            HSSFCellStyle styleContentR = SheetStyle.GetStyle(workbook, CellPosition.Right);//右

            styleContentR.SetFont(fontContent);
            HSSFCellStyle styleContentC = SheetStyle.GetStyle(workbook, CellPosition.Center);//中

            styleContentC.SetFont(fontContent);
            HSSFCellStyle styleContentLB = SheetStyle.GetStyle(workbook, CellPosition.LeftBottom);//左下

            styleContentLB.SetFont(fontContent);
            HSSFCellStyle styleContentRB = SheetStyle.GetStyle(workbook, CellPosition.RightBottom);//右下

            styleContentRB.SetFont(fontContent);
            HSSFCellStyle styleContentB = SheetStyle.GetStyle(workbook, CellPosition.Bottom);//下

            styleContentB.SetFont(fontContent);

            //标题
            HSSFRow  rowTitle  = (HSSFRow)sheet.CreateRow(0);
            HSSFCell cellTitle = (HSSFCell)rowTitle.CreateCell(0);

            rowTitle.HeightInPoints = 46.5F;                                       //设置行高
            cellTitle.CellStyle     = styleTitle;                                  //设置标题样式
            cellTitle.SetCellValue(Title);                                         //给标题位置赋值
            cellTitle.CellStyle = styleTitle;
            sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, columnCount - 1)); //合并单元格,行为一行,列为DataGrid的列数

            int num_date = 1;                                                      //判断是否有日期这一行

            //制表时间
            if (!string.IsNullOrEmpty(date))
            {
                HSSFRow rowDate = (HSSFRow)sheet.CreateRow(num_date);
                rowDate.HeightInPoints = 19.5F;
                HSSFCell cellDate = (HSSFCell)rowDate.CreateCell(columnCount - 2);//位置在列数减2的格上
                cellDate.CellStyle = styleDate;
                cellDate.SetCellValue(date);
                sheet.AddMergedRegion(new CellRangeAddress(1, 1, columnCount - 2, columnCount - 1));
                num_date++;
            }

            //添加表头
            HSSFRow rowHeader = (HSSFRow)sheet.CreateRow(num_date);

            rowHeader.HeightInPoints = 30;
            for (int i = 0; i < columnCount; i++)
            {
                HSSFCell cellHeader = (HSSFCell)rowHeader.CreateCell(i);
                if (i == 0)
                {
                    cellHeader.CellStyle = styleHeaderLT;
                }
                else if (i == columnCount - 1)
                {
                    cellHeader.CellStyle = styleHeaderRT;
                }
                else
                {
                    cellHeader.CellStyle = styleHeaderT;
                }
                cellHeader.SetCellValue(dg.Columns[i].Header.ToString());//给表头位置赋值
            }

            //添加内容
            for (int i = 0; i < rowCount; i++)
            {
                HSSFRow rowContent = (HSSFRow)sheet.CreateRow(num_date + i + 1);
                rowContent.HeightInPoints = 37;
                for (int j = 0; j < columnCount; j++)
                {
                    HSSFCell cellContent = (HSSFCell)rowContent.CreateCell(j);
                    if (j == 0)
                    {
                        if (i == rowCount - 1)
                        {
                            cellContent.CellStyle = styleContentLB;
                        }
                        else
                        {
                            cellContent.CellStyle = styleContentL;
                        }
                    }
                    else if (j == columnCount - 1)
                    {
                        if (i == rowCount - 1)
                        {
                            cellContent.CellStyle = styleContentRB;
                        }
                        else
                        {
                            cellContent.CellStyle = styleContentR;
                        }
                    }
                    else
                    {
                        if (i == rowCount - 1)
                        {
                            cellContent.CellStyle = styleContentB;
                        }
                        else
                        {
                            cellContent.CellStyle = styleContentC;
                        }
                    }
                    DataGridCell cell = dg.GetCell(i, j);
                    cellContent.SetCellValue((dg.GetCell(i, j).Content as TextBlock).Text);
                }
            }

            //string outputPath = @"E://abc.xls";
            try
            {
                SaveFileDialog sfd = new SaveFileDialog()
                {
                    DefaultExt  = "xls",
                    Filter      = "xls Files (*.xls)|*.xls|All files (*.*)|*.*",
                    FilterIndex = 1
                };
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    // using (Stream stream = sfd.OpenFile())
                    {
                        FileStream outStream = new FileStream(sfd.FileName, FileMode.Create);
                        workbook.Write(outStream);
                        outStream.Close();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("保存失败!");
                Console.WriteLine(e.Message);
            }
        }