using PaintDotNet.Base.Functionodel; using PaintDotNet.Base.CommTool; using PaintDotNet.CustomControl; using PaintDotNet.DbOpreate.DbBll; using PaintDotNet.DbOpreate.DbModel; using PaintDotNet.Base.SettingModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using static PaintDotNet.Base.Functionodel.AnalyzeSettingModel; using APIDialogs = Microsoft.WindowsAPICodePack.Dialogs; using System.Drawing.Imaging; using System.Runtime.Serialization.Formatters.Binary; using OpenCvSharp.Extensions; namespace PaintDotNet { /// /// 通用分析模板设置页 /// internal class MeasureListSettingDialog : PdnBaseForm { #region 控件 private GroupBox groupBox1; private Button button2; private Button button1; private GroupBox groupBox2; private ComboBox comboBox1; private Label label3; private Label label2; private Label label1; private GroupBox groupBox3; private GroupBox groupBox4; private GroupBox groupBox5; private Button button3; private TextBox textBox1; private Label label6; private Label label5; private Label label4; private TextBox textBox2; private Label label8; private Label label7; private Label label12; private TextBox textBox6; private Label label11; private TextBox textBox5; private Label label10; private TextBox textBox4; private Label label9; private DataGridView dataGridView1; private TextBox textBox9; private Label label14; private TextBox textBox8; private Label label13; private Button button4; private DateTimePicker dateTimePicker1; private DateTimePicker dateTimePicker2; private GroupBox groupBox6; private Button button5; #endregion /// /// 数据库对应字段 /// private string languageName; /// /// 数据库对应list /// private List infosList; /// /// 功能路径名称,因需递归作为全局对象 /// private string functionPathMsg; /// /// 分类名称,主要供书签使用 /// private string analyzeClassify; /// /// 调用当前窗口的对象 /// private PdnBaseForm pdnBaseForm; /// /// 在打开窗体时辅助判断是否存在报告模板文件 /// public bool hasModule = false; /// /// xml对应文件路径 /// private string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\" + "AnalyzeSavedModel.xml"; /// /// xml对象 /// private AnalyzeSavedModel analyzeSavedModel; /// /// 当前分析分类的数据 /// private AnalyzeSavedModel.ModelItem analyzeModel; /// /// 主控件 /// private AppWorkspace appWorkspace; /// /// 导出数据 /// private DataTable dataTable; private bool exportImg; public MeasureListSettingDialog(PdnBaseForm form, string languageName, AppWorkspace appWorkspace, DataTable dataTable,bool exportImg = false) { this.languageName = languageName; this.pdnBaseForm = form; this.appWorkspace = appWorkspace; this.dataTable = dataTable; infosList = mic_template_infos_BLL.FindAll();//查询出所有模板分类对象 InitializeComponent(); InitializeLanguageText(); InitGridHeader(); InitOtherInfo(); InitLastTimeInfo(); this.exportImg = exportImg; if (this.languageName.Equals("Template.Manager.item1.MeasureListAll")) { this.groupBox4.Visible = false; this.groupBox5.Visible = false; this.groupBox6.Visible = false; this.button5.Visible = false; this.Height = 279; } else { this.groupBox4.Visible = true; this.groupBox5.Visible = true; this.groupBox6.Visible = true; this.button5.Visible = true; this.Height = 670; } if (this.languageName == "Template.Manager.item2.AtlasComparison") this.button5.Enabled = false; } #region 初始化 private void InitializeLanguageText() { this.button5.Text = PdnResources.GetString("Menu.Configurehebookmark.Text"); this.label3.Text = PdnResources.GetString("Menu.Pleaseselectthetemplateyoucanuse.Text") + ":"; this.label2.Text = PdnResources.GetString("Menu.nothing.Text"); this.label1.Text = PdnResources.GetString("Menu.Thefunctionpath.Text") + ":"; this.groupBox3.Text = PdnResources.GetString("Menu.Itemstoragepathselection.Text"); this.label6.Text = PdnResources.GetString("Menu.nothing.Text"); this.label5.Text = PdnResources.GetString("Menu.Thespecificpath.Text") + ":"; this.label4.Text = PdnResources.GetString("Menu.Storagepath.Text") + ":"; this.groupBox4.Text = PdnResources.GetString("Menu.thebasicinformationofproject.text"); this.label8.Text = PdnResources.GetString("Menu.projectnumber.text") + ":"; this.label7.Text = PdnResources.GetString("Menu.Ratingdate.text") + ":"; this.groupBox5.Text = PdnResources.GetString("Menu.Ratingdate.text"); this.label12.Text = PdnResources.GetString("Menu.Inspectiondate.text") + ":"; this.label11.Text = PdnResources.GetString("Menu.Contactperson.text") + ":"; this.label10.Text = PdnResources.GetString("Menu.inspectiondepartment.text") + ":"; this.label9.Text = PdnResources.GetString("Menu.Sender.text") + ":"; this.groupBox6.Text = PdnResources.GetString("Menu.other.text"); this.label14.Text = PdnResources.GetString("Menu.name.text") + ":"; this.label13.Text = PdnResources.GetString("Menu.content.text") + ":"; this.button4.Text = PdnResources.GetString("Menu.Addto.text"); this.Text = PdnResources.GetString("Menu.Analysisofsetting.Text"); this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); if (this.languageName.Equals("Template.Manager.item1.MeasureListAll")) this.button2.Text = PdnResources.GetString("Menu.Exportresults.text"); else this.button2.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text"); this.button1.Text = PdnResources.GetString("Menu.File.Close.Text"); this.groupBox2.Text = PdnResources.GetString("Menu.Reporttemplateselection.Text"); } private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.button5 = new System.Windows.Forms.Button(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.button3 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker(); this.label12 = new System.Windows.Forms.Label(); this.textBox6 = new System.Windows.Forms.TextBox(); this.label11 = new System.Windows.Forms.Label(); this.textBox5 = new System.Windows.Forms.TextBox(); this.label10 = new System.Windows.Forms.Label(); this.textBox4 = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.textBox9 = new System.Windows.Forms.TextBox(); this.label14 = new System.Windows.Forms.Label(); this.textBox8 = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); this.button4 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.groupBox6.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(12, 4); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(542, 49); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // button2 // this.button2.BackColor = System.Drawing.SystemColors.Control; this.button2.Location = new System.Drawing.Point(416, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(111, 30); this.button2.TabIndex = 1; this.button2.Text = "生成报告"; this.button2.UseVisualStyleBackColor = false; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.BackColor = System.Drawing.SystemColors.Control; this.button1.Location = new System.Drawing.Point(334, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(76, 30); this.button1.TabIndex = 0; this.button1.Text = "关闭"; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.button5); this.groupBox2.Controls.Add(this.comboBox1); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Location = new System.Drawing.Point(12, 56); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(542, 90); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "报告模板选择"; // // button5 // this.button5.Location = new System.Drawing.Point(467, 57); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(65, 20); this.button5.TabIndex = 4; this.button5.Text = "配置书签"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(163, 56); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(298, 20); this.comboBox1.TabIndex = 3; // // label3 // this.label3.AutoSize = true; this.label3.ForeColor = System.Drawing.SystemColors.ControlText; this.label3.Location = new System.Drawing.Point(17, 61); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(125, 12); this.label3.TabIndex = 2; this.label3.Text = "请选择可使用的模板:"; // // label2 // this.label2.AutoSize = true; this.label2.ForeColor = System.Drawing.SystemColors.ControlText; this.label2.Location = new System.Drawing.Point(163, 26); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(107, 12); this.label2.TabIndex = 1; this.label2.Text = "通用分析-多相含量"; // // label1 // this.label1.AutoSize = true; this.label1.ForeColor = System.Drawing.SystemColors.ControlText; this.label1.Location = new System.Drawing.Point(17, 26); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); this.label1.TabIndex = 0; this.label1.Text = "功能路径:"; // // groupBox3 // this.groupBox3.Controls.Add(this.button3); this.groupBox3.Controls.Add(this.textBox1); this.groupBox3.Controls.Add(this.label6); this.groupBox3.Controls.Add(this.label5); this.groupBox3.Controls.Add(this.label4); this.groupBox3.Location = new System.Drawing.Point(12, 162); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(542, 77); this.groupBox3.TabIndex = 1; this.groupBox3.TabStop = false; this.groupBox3.Text = "项目储存路径选择"; // // button3 // this.button3.BackColor = System.Drawing.SystemColors.Window; this.button3.Font = new System.Drawing.Font("宋体", 6F); this.button3.Location = new System.Drawing.Point(498, 45); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(29, 21); this.button3.TabIndex = 5; this.button3.Text = "..."; this.button3.UseVisualStyleBackColor = false; this.button3.Click += new System.EventHandler(this.button3_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(103, 45); this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true; this.textBox1.Size = new System.Drawing.Size(400, 21); this.textBox1.TabIndex = 4; // // label6 // this.label6.AutoSize = true; this.label6.ForeColor = System.Drawing.SystemColors.ControlText; this.label6.Location = new System.Drawing.Point(101, 25); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(0, 12); this.label6.TabIndex = 3; // // label5 // this.label5.AutoSize = true; this.label5.ForeColor = System.Drawing.SystemColors.ControlText; this.label5.Location = new System.Drawing.Point(18, 51); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(65, 12); this.label5.TabIndex = 2; this.label5.Text = "具体路径:"; // // label4 // this.label4.AutoSize = true; this.label4.ForeColor = System.Drawing.SystemColors.ControlText; this.label4.Location = new System.Drawing.Point(18, 25); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(65, 12); this.label4.TabIndex = 1; this.label4.Text = "储存路径:"; // // groupBox4 // this.groupBox4.Controls.Add(this.dateTimePicker1); this.groupBox4.Controls.Add(this.textBox2); this.groupBox4.Controls.Add(this.label8); this.groupBox4.Controls.Add(this.label7); this.groupBox4.Location = new System.Drawing.Point(12, 240); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(542, 60); this.groupBox4.TabIndex = 1; this.groupBox4.TabStop = false; this.groupBox4.Text = "项目基本信息"; // // dateTimePicker1 // this.dateTimePicker1.Location = new System.Drawing.Point(346, 24); this.dateTimePicker1.Name = "dateTimePicker1"; this.dateTimePicker1.Size = new System.Drawing.Size(165, 21); this.dateTimePicker1.TabIndex = 6; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(92, 24); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(165, 21); this.textBox2.TabIndex = 5; // // label8 // this.label8.AutoSize = true; this.label8.ForeColor = System.Drawing.SystemColors.ControlText; this.label8.Location = new System.Drawing.Point(18, 28); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(65, 12); this.label8.TabIndex = 4; this.label8.Text = "项目编号:"; // // label7 // this.label7.AutoSize = true; this.label7.ForeColor = System.Drawing.SystemColors.ControlText; this.label7.Location = new System.Drawing.Point(283, 28); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(65, 12); this.label7.TabIndex = 3; this.label7.Text = "评级日期:"; // // groupBox5 // this.groupBox5.Controls.Add(this.dateTimePicker2); this.groupBox5.Controls.Add(this.label12); this.groupBox5.Controls.Add(this.textBox6); this.groupBox5.Controls.Add(this.label11); this.groupBox5.Controls.Add(this.textBox5); this.groupBox5.Controls.Add(this.label10); this.groupBox5.Controls.Add(this.textBox4); this.groupBox5.Controls.Add(this.label9); this.groupBox5.Location = new System.Drawing.Point(12, 301); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(542, 90); this.groupBox5.TabIndex = 1; this.groupBox5.TabStop = false; this.groupBox5.Text = "评级日期"; // // dateTimePicker2 // this.dateTimePicker2.Location = new System.Drawing.Point(346, 58); this.dateTimePicker2.Name = "dateTimePicker2"; this.dateTimePicker2.Size = new System.Drawing.Size(165, 21); this.dateTimePicker2.TabIndex = 14; // // label12 // this.label12.AutoSize = true; this.label12.ForeColor = System.Drawing.SystemColors.ControlText; this.label12.Location = new System.Drawing.Point(283, 62); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(53, 12); this.label12.TabIndex = 13; this.label12.Text = "送检日期"; // // textBox6 // this.textBox6.Location = new System.Drawing.Point(346, 23); this.textBox6.Name = "textBox6"; this.textBox6.Size = new System.Drawing.Size(165, 21); this.textBox6.TabIndex = 12; // // label11 // this.label11.AutoSize = true; this.label11.ForeColor = System.Drawing.SystemColors.ControlText; this.label11.Location = new System.Drawing.Point(283, 28); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(53, 12); this.label11.TabIndex = 11; this.label11.Text = "联系人:"; // // textBox5 // this.textBox5.Location = new System.Drawing.Point(92, 58); this.textBox5.Name = "textBox5"; this.textBox5.Size = new System.Drawing.Size(165, 21); this.textBox5.TabIndex = 10; // // label10 // this.label10.AutoSize = true; this.label10.ForeColor = System.Drawing.SystemColors.ControlText; this.label10.Location = new System.Drawing.Point(18, 62); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(65, 12); this.label10.TabIndex = 9; this.label10.Text = "送检单位:"; // // textBox4 // this.textBox4.Location = new System.Drawing.Point(92, 23); this.textBox4.Name = "textBox4"; this.textBox4.Size = new System.Drawing.Size(165, 21); this.textBox4.TabIndex = 8; // // label9 // this.label9.AutoSize = true; this.label9.ForeColor = System.Drawing.SystemColors.ControlText; this.label9.Location = new System.Drawing.Point(18, 28); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(53, 12); this.label9.TabIndex = 7; this.label9.Text = "送检人:"; // // groupBox6 // this.groupBox6.Controls.Add(this.dataGridView1); this.groupBox6.Controls.Add(this.textBox9); this.groupBox6.Controls.Add(this.label14); this.groupBox6.Controls.Add(this.textBox8); this.groupBox6.Controls.Add(this.label13); this.groupBox6.Controls.Add(this.button4); this.groupBox6.Location = new System.Drawing.Point(12, 393); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(542, 226); this.groupBox6.TabIndex = 1; this.groupBox6.TabStop = false; this.groupBox6.Text = "其他"; // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AllowUserToDeleteRows = false; this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView1.BackgroundColor = System.Drawing.Color.White; this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; this.dataGridView1.Location = new System.Drawing.Point(16, 68); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.Size = new System.Drawing.Size(511, 148); this.dataGridView1.TabIndex = 19; this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); // // textBox9 // this.textBox9.Location = new System.Drawing.Point(55, 30); this.textBox9.Name = "textBox9"; this.textBox9.Size = new System.Drawing.Size(165, 21); this.textBox9.TabIndex = 18; // // label14 // this.label14.AutoSize = true; this.label14.ForeColor = System.Drawing.SystemColors.ControlText; this.label14.Location = new System.Drawing.Point(14, 34); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(41, 12); this.label14.TabIndex = 17; this.label14.Text = "名称:"; // // textBox8 // this.textBox8.Location = new System.Drawing.Point(268, 30); this.textBox8.Name = "textBox8"; this.textBox8.Size = new System.Drawing.Size(165, 21); this.textBox8.TabIndex = 16; // // label13 // this.label13.AutoSize = true; this.label13.ForeColor = System.Drawing.SystemColors.ControlText; this.label13.Location = new System.Drawing.Point(228, 34); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(41, 12); this.label13.TabIndex = 15; this.label13.Text = "内容:"; // // button4 // this.button4.BackColor = System.Drawing.SystemColors.Control; this.button4.Location = new System.Drawing.Point(451, 25); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(76, 30); this.button4.TabIndex = 2; this.button4.Text = "添加"; this.button4.UseVisualStyleBackColor = false; this.button4.Click += new System.EventHandler(this.button4_Click); // // MeasureListSettingDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.BackColor = System.Drawing.SystemColors.Control; this.ClientSize = new System.Drawing.Size(566, 631); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "MeasureListSettingDialog"; this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox4, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); } /// /// 初始化表头 /// private void InitGridHeader() { this.dataGridView1.ColumnHeadersHeight = 25; DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn(); h1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h1.Width = 200; DataGridViewTextBoxColumn h2 = new DataGridViewTextBoxColumn(); h2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h2.Width = 200; DataGridViewButtonColumn h3 = new DataGridViewButtonColumn(); h3.Width = 90; this.dataGridView1.Columns.Add(h1); this.dataGridView1.Columns.Add(h2); this.dataGridView1.Columns.Add(h3); DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1); helper.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.name.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, PdnResources.GetString("Menu.content.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, PdnResources.GetString("Menu.operation.text"))); this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView1.Columns[0].ReadOnly = true; this.dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView1.Columns[1].ReadOnly = true; this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.AllowUserToResizeColumns = false; } /// /// 初始化其他信息 /// private void InitOtherInfo() { //设置功能路径名称 if (this.languageName.Contains("Template.Manager")) functionPathMsg = PdnResources.GetString(this.languageName); else functionPathMsg = this.languageName; this.analyzeClassify = functionPathMsg; this.Text = this.analyzeClassify + PdnResources.GetString("Menu.Thereportisset.Text"); getFullLanguagePath(this.languageName); this.label2.Text = functionPathMsg; //设置模板下拉菜单 mic_template_infos infoModel = infosList.Find(a => a.language_name == this.languageName); string filePath = Application.StartupPath + "\\ModuleManage" + infoModel.template_path.Replace('/', '\\');//获取文档路径 if (Directory.Exists(filePath)) { string[] fileNames = Directory.GetFiles(filePath); Dictionary moduleInfo = new Dictionary(); for (int i = 0; i < fileNames.Count(); i++) { //编辑时产生的临时文件,不统计 if (Path.GetFileName(fileNames[i]).Contains("~$")) continue; if (this.languageName.Equals("Template.Manager.item1.MeasureListAll")) { //判断是excel文件 if (FileOperationHelper.IsFileWordOrExcel(fileNames[i]) == 2) moduleInfo.Add(Path.GetFileNameWithoutExtension(fileNames[i]), fileNames[i]); } else { //判断是word文件 if (FileOperationHelper.IsFileWordOrExcel(fileNames[i]) == 1) moduleInfo.Add(Path.GetFileNameWithoutExtension(fileNames[i]), fileNames[i]); } } //绑定下拉菜单 if (moduleInfo.Count > 0) { BindingSource bs = new BindingSource(); bs.DataSource = moduleInfo; this.comboBox1.DataSource = bs; this.comboBox1.ValueMember = "Value"; this.comboBox1.DisplayMember = "Key"; hasModule = true; } else MessageBox.Show(PdnResources.GetString("Menu.Therearenoatefirst.text")); } else MessageBox.Show(PdnResources.GetString("Menu.Therearenoatefirst.text")); //设置存储路径 string[] savePathArr = infoModel.template_path.Split('/');//拆分以获取路径根目录的名称 ConfigModel configModel = Startup.instance.configModel; if (savePathArr[1].Equals("Conventional")) this.label6.Text = configModel.NormalOperation; else if (savePathArr[1].Equals("Universal")) this.label6.Text = configModel.GeneralAnalysis; else if (savePathArr[1].Equals("Dedicated")) this.label6.Text = configModel.DedicatedAnalysis; else this.label6.Text = PdnResources.GetString("Menu.Pathacquisitionerror.Text"); if (string.IsNullOrEmpty(this.label6.Text)) this.label6.Text = PdnResources.GetString("Menu.Thestoragepathisnotset.Text"); } /// /// 加载之前保存的信息 /// private void InitLastTimeInfo() { if (this.hasModule && System.IO.File.Exists(filePath)) { analyzeSavedModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); if (analyzeSavedModel.modelItems != null && analyzeSavedModel.modelItems.Count > 0) { analyzeModel = analyzeSavedModel.modelItems.Find(a => a.languageName == this.languageName); if (analyzeModel != null && analyzeModel.analyzeSettingModel != null) { if (!string.IsNullOrEmpty(analyzeModel.analyzeSettingModel.modulePath)) this.comboBox1.SelectedValue = analyzeModel.analyzeSettingModel.modulePath; if (!string.IsNullOrEmpty(analyzeModel.analyzeSettingModel.savePath)) this.textBox1.Text = analyzeModel.analyzeSettingModel.savePath; if (!string.IsNullOrEmpty(analyzeModel.analyzeSettingModel.itemNumber)) this.textBox2.Text = analyzeModel.analyzeSettingModel.itemNumber; if (!string.IsNullOrEmpty(analyzeModel.analyzeSettingModel.inspectionPerson)) this.textBox4.Text = analyzeModel.analyzeSettingModel.inspectionPerson; if (!string.IsNullOrEmpty(analyzeModel.analyzeSettingModel.contact)) this.textBox6.Text = analyzeModel.analyzeSettingModel.contact; if (!string.IsNullOrEmpty(analyzeModel.analyzeSettingModel.inspectionDepartment)) this.textBox5.Text = analyzeModel.analyzeSettingModel.inspectionDepartment; if (analyzeModel.analyzeSettingModel.inspectionDate != DateTime.MinValue) this.dateTimePicker2.Value = analyzeModel.analyzeSettingModel.inspectionDate; if (analyzeModel.analyzeSettingModel.otherList != null && analyzeModel.analyzeSettingModel.otherList.Count > 0) { foreach (OthersInfo info in analyzeModel.analyzeSettingModel.otherList) { DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(CreateTextBoxCell(info.name, "name")); row.Cells.Add(CreateTextBoxCell(info.content, "content")); row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Edit.Delete.Text"), "delete")); this.dataGridView1.Rows.Add(row); } this.dataGridView1.ClearSelection(); } } } } } #endregion /// /// 递归拼接功能路径的全称 /// /// private void getFullLanguagePath(string name) {//Template.Manager.item3.GrainSizeCutOff6394Method mic_template_infos infoModel = infosList.Find(a => a.language_name == name); //如果有上级,查询出上级的name对应的实际名称,拼接到前面,然后继续递归 if (infoModel.parent_id != 0) { string parentLanguageName = infosList.Find(a => a.id == infoModel.parent_id).language_name; if (parentLanguageName.Contains("Template.Manager")) functionPathMsg = PdnResources.GetString(parentLanguageName) + "-" + functionPathMsg; else functionPathMsg = parentLanguageName + "-" + functionPathMsg; getFullLanguagePath(parentLanguageName); } } /// /// 路径选择 /// /// /// private void button3_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); //if (!this.label6.Text.Equals("路径获取错误") && !this.label6.Text.Equals("存储路径未设置") && !this.label6.Text.Equals("无")) //{ // dialog.SelectedPath = this.label6.Text + "\\" + this.analyzeClassify + "\\"; //} //else //{ // //} dialog.SelectedPath = this.label6.Text; if (dialog.ShowDialog() == DialogResult.OK) { this.textBox1.Text = dialog.SelectedPath; } /*APIDialogs.CommonOpenFileDialog dialog = new APIDialogs.CommonOpenFileDialog(); dialog.IsFolderPicker = true; dialog.EnsurePathExists = true; if(this.label6.Text.Equals("路径获取错误") || this.label6.Text.Equals("存储路径未设置") || this.label6.Text.Equals("无")) dialog.InitialDirectory = "C:\\"; else dialog.InitialDirectory = this.label6.Text; if (dialog.ShowDialog() == APIDialogs.CommonFileDialogResult.Ok) { this.textBox1.Text = dialog.FileName; }*/ } /// /// 关闭按钮 /// /// /// private void button1_Click(object sender, EventArgs e) { this.Close(); } /// /// 保存按钮 /// /// /// private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBox1.Text)) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectaspecificstoragepath.text")); return; } if (this.comboBox1.SelectedValue == null) { MessageBox.Show(PdnResources.GetString("Menu.Therearenorecannotbesaved.text") + "!"); return; } AnalyzeSettingModel model = new AnalyzeSettingModel(); model.modulePath = this.comboBox1.SelectedValue.ToString(); model.savePath = this.textBox1.Text; model.itemNumber = this.textBox2.Text; model.ratingDate = this.dateTimePicker1.Value; model.inspectionPerson = this.textBox4.Text; model.contact = this.textBox6.Text; model.inspectionDepartment = this.textBox5.Text; model.inspectionDate = this.dateTimePicker2.Value; model.analyzeClassify = this.analyzeClassify; if (this.dataGridView1.Rows.Count > 0) { model.otherList = new List(); foreach (DataGridViewRow rowData in this.dataGridView1.Rows) { OthersInfo othersInfo = new OthersInfo(); othersInfo.name = rowData.Cells[0].Value.ToString(); othersInfo.content = rowData.Cells[1].Value.ToString(); model.otherList.Add(othersInfo); } } if (analyzeSavedModel != null) { if (analyzeModel != null) analyzeModel.analyzeSettingModel = model; else { analyzeModel = new AnalyzeSavedModel.ModelItem(); analyzeModel.languageName = this.languageName; analyzeModel.analyzeSettingModel = model; analyzeSavedModel.modelItems.Add(analyzeModel); } } else { analyzeSavedModel = new AnalyzeSavedModel(); analyzeSavedModel.modelItems = new List(); analyzeModel = new AnalyzeSavedModel.ModelItem(); analyzeModel.languageName = this.languageName; analyzeModel.analyzeSettingModel = model; analyzeSavedModel.modelItems.Add(analyzeModel); } //保存xml文件 string savedModelInfo = XmlSerializeHelper.XmlSerialize(analyzeSavedModel); if (FileOperationHelper.WriteStringToFile(savedModelInfo, filePath, FileMode.Create)) { //将对象传递回调用页面 this.pdnBaseForm.AnalyzeSettingModel = model; this.analyzeSettingModel = model; GeneratingReports(); this.Close(); } else { MessageBox.Show(PdnResources.GetString("Menu.Savefailed.text")); } } Dictionary pNames = new Dictionary(); /// /// 保存图片到本地 /// /// private void SaveAllImage(List bitList, string newPath, int originNum , int codeNum, string pName) { if (bitList != null && bitList.Count > 0) { for (int i = 0; i < bitList.Count; i++) { string bitPath = ""; //分别为原图和处理后的图命名 if (i % 2 == 0) { bitPath = newPath + "/" + "origin" + originNum + ".jpg"; pNames.Add("origin" + originNum, pName); } else { bitPath = newPath + "/" + codeNum + ".jpg"; pNames.Add(codeNum.ToString(), pName); } bitList[i].Save(bitPath); } } } /// /// 生成报告 /// /// /// private void GeneratingReports() { if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { //获取word书签与excel单元格的关系,以字典方式存储 List mic_module_infos = mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify); Dictionary tagInfos = new Dictionary(); if (mic_module_infos != null && mic_module_infos.Count > 0) { foreach (mic_module_infos info in mic_module_infos) { tagInfos.Add(info.tag_name, info.cell_position); } } List> analysisContent = new List>(); for (int i = 0; i < this.dataTable.Rows.Count; i++) { List content1 = new List(); for (int c = 0; c < this.dataTable.Columns.Count; c++) { content1.Add(this.dataTable.Rows[i][c].ToString()); } analysisContent.Add(content1); } if (this.languageName.Equals("Template.Manager.item1.MeasureListAll")) { int drawCount = 0; for (int i = this.appWorkspace.DocumentWorkspaces.Length - 1; i >= 0; i--) { drawCount += this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Count; } if (drawCount == 0) { MessageBox.Show("没有测量信息!"); return; } ProgressThreadProcClass procClass = new ProgressThreadProcClass(); System.Threading.ThreadStart copyThreadProc = delegate () { string saveAsPath = ""; if (System.IO.File.Exists(analyzeSettingModel.modulePath)) { saveAsPath = analyzeSettingModel.savePath + "\\" + analyzeSettingModel.analyzeClassify //+ "分析" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";//另存的excel文件名 //如果savePath是盘符不是文件夹,会多出一个斜杠,office的saveas无法识别,固需处理一下 if (saveAsPath.IndexOf("\\\\") != -1) saveAsPath = saveAsPath.Replace("\\\\", "\\"); if (analysisContent != null) { try { string dictPath = Application.StartupPath + "\\temp"; if(!System.IO.Directory.Exists(dictPath)) { System.IO.Directory.CreateDirectory(dictPath); } DeleteFolder(dictPath); pNames = new Dictionary(); int insertIn = 0; //保存处理后的图片 for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++) { if (this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Count == 0) continue; List tempBit = new List(); Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap(); Bitmap processedBit1; Bitmap newBit1 = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); if (this.appWorkspace.DocumentWorkspaces[i].PhaseModels.Count > 0) { foreach (var item in this.appWorkspace.DocumentWorkspaces[i].PhaseModels) { processedBit1 = BitmapConverter.ToBitmap(item.mat); Graphics graphics = Graphics.FromImage(newBit1); graphics.DrawImage(processedBit1, new PointF(0, 0)); } } tempBit.Add(newBit1); Bitmap processedBit; Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); if(this.appWorkspace.DocumentWorkspaces[i].PhaseModels.Count > 0) { foreach (var item in this.appWorkspace.DocumentWorkspaces[i].PhaseModels) { processedBit = BitmapConverter.ToBitmap(item.mat); Graphics graphics = Graphics.FromImage(newBit); graphics.DrawImage(processedBit, new PointF(0, 0)); this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Draw(graphics); } } else { processedBit = this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap(); Graphics graphics = Graphics.FromImage(newBit); graphics.DrawImage(processedBit, new PointF(0, 0)); this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Draw(graphics); } tempBit.Add(newBit); string imgName = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); this.SaveAllImage(tempBit, dictPath, insertIn + 1, insertIn + 1, imgName); insertIn++; } bool su = OfficeFileHandleHelper.SaveAsExcelWithModule(analyzeSettingModel.modulePath, saveAsPath, analysisContent, dictPath, pNames, isJiaoHu : true); ; procClass.DismissProgressAction(this); if (su) MessageBox.Show(PdnResources.GetString("Menu.MeasureDatafoldertoview.text")); } catch (Exception) { MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text")); } finally { procClass.DismissProgressAction(this); } } } }; procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text")); } else { List bitList = new List(); //保存图片,保存原路径、原文件名、原保存格式、不压缩、保存后不关闭图像 Bitmap bitmap = this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(); Bitmap newBitmap; if (this.appWorkspace.ActiveDocumentWorkspace.phaseModels != null && this.appWorkspace.ActiveDocumentWorkspace.phaseModels.Count > 0 && this.appWorkspace.ActiveDocumentWorkspace.phaseModels[0].mat != null) { newBitmap = DeepClone(BitmapConverter.ToBitmap(this.appWorkspace.ActiveDocumentWorkspace.phaseModels[0].mat)); } else { newBitmap = DeepClone(bitmap); } Graphics graphics = Graphics.FromImage(newBitmap); //标注及测量信息嵌入图像 if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList != null && this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0) { this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Draw(graphics); } bitList.Add(newBitmap); this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos); } } else MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text") + "!"); } public void DeleteFolder(string path) { foreach (string d in Directory.GetFileSystemEntries(path)) { if (System.IO.File.Exists(d)) { FileInfo fi = new FileInfo(d); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) fi.Attributes = FileAttributes.Normal; System.IO.File.Delete(d);//直接删除其中的文件 } else { DirectoryInfo d1 = new DirectoryInfo(d); if (d1.GetFiles().Length != 0) { DeleteFolder(d1.FullName); } Directory.Delete(d); } } } public Bitmap DeepClone(Bitmap bitmap) { Bitmap dstBitmap = null; using (MemoryStream mStream = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(mStream, bitmap); mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。 dstBitmap = (Bitmap)bf.Deserialize(mStream); mStream.Close(); } return dstBitmap; } /// /// 添加按钮-其他 /// /// /// private void button4_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBox9.Text)) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseenteranameofthephase.text")); return; } if (string.IsNullOrEmpty(this.textBox8.Text)) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseentercontent.text")); return; } DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(CreateTextBoxCell(this.textBox9.Text, "name")); row.Cells.Add(CreateTextBoxCell(this.textBox8.Text, "content")); row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Edit.Delete.Text"), "delete")); this.dataGridView1.Rows.Add(row); //选中最新添加的那一条 this.dataGridView1.ClearSelection(); this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Selected = true; //清空输入框 this.textBox9.Text = ""; this.textBox8.Text = ""; } /// /// 添加内容单元格 /// /// /// /// private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag) { DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell(); textboxcell.Value = text; textboxcell.Tag = tag; return textboxcell; } /// /// 添加按钮单元格 /// /// /// /// public DataGridViewButtonCell CreateButtonCell(string text, object tag) { DataGridViewButtonCell buttonCell = new DataGridViewButtonCell(); buttonCell.Value = text; buttonCell.Tag = tag; return buttonCell; } /// /// 点击datagridview的删除按钮 /// /// /// private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[e.RowIndex]); } /// /// 配置书签按钮 /// /// /// private void button5_Click(object sender, EventArgs e) { BookmarkConfigDialog bookmarkConfigDialog = new BookmarkConfigDialog(this.analyzeClassify,this.languageName); bookmarkConfigDialog.StartPosition = FormStartPosition.CenterParent; bookmarkConfigDialog.ShowDialog(); } } }