using PaintDotNet.Base.CommTool; using PaintDotNet.Base.Functionodel; using PaintDotNet.Base.SettingModel; using PaintDotNet.CustomControl; using PaintDotNet.DbOpreate.DbBll; using PaintDotNet.DbOpreate.DbModel; 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.Tasks; using System.Windows.Forms; using static PaintDotNet.Base.Functionodel.AnalyzeSettingModel; namespace PaintDotNet.Instrument { public partial class CreateProjectDialog : PdnBaseForm { #region 控件 private GroupBox groupBox1; private Button button2; private Button button1; private GroupBox groupBox6; private DataGridView dataGridView1; private TextBox textBox9; private Label label14; private TextBox textBox8; private Label label13; private Button button4; private GroupBox groupBox5; private DateTimePicker dateTimePicker2; private Label label12; private TextBox textBox6; private Label label11; private TextBox textBox5; private Label label10; private TextBox textBox4; private Label label9; private GroupBox groupBox4; private DateTimePicker dateTimePicker1; private TextBox textBox2; private Label label8; private Label label7; #endregion /// /// 数据 /// public AnalyzeSettingModel model; /// /// 父窗口 /// public PdnBaseForm pdnBaseForm; /// /// 上级id /// public int parentId; public CreateProjectDialog(PdnBaseForm pdnBaseForm) { this.pdnBaseForm = pdnBaseForm; this.model = new AnalyzeSettingModel(); InitializeComponent(); InitializeLanguageText(); InitGridHeader(); InitializeModelData(); } private void InitializeLanguageText() { this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.button2.Text = PdnResources.GetString("Menu.File.Save.Text"); this.button1.Text = PdnResources.GetString("Menu.File.Close.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.groupBox5.Text = PdnResources.GetString("Menu.Inspectioninformation.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.groupBox4.Text = PdnResources.GetString("Menu.thebasicinformationofproject.text"); this.label8.Text = PdnResources.GetString("Menu.projectnumber.text") + ":"; this.label7.Text = PdnResources.GetString("Menu.Ratingdate.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.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.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.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.groupBox1.SuspendLayout(); this.groupBox6.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox5.SuspendLayout(); this.groupBox4.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(542, 49); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // button2 // this.button2.BackColor = System.Drawing.SystemColors.Control; this.button2.Location = new System.Drawing.Point(460, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(76, 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(378, 13); 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); // // 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, 220); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(542, 226); this.groupBox6.TabIndex = 2; 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); // // 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, 128); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(542, 90); this.groupBox5.TabIndex = 3; 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(65, 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(30, 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(30, 28); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(53, 12); this.label9.TabIndex = 7; this.label9.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, 67); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(542, 60); this.groupBox4.TabIndex = 4; 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(30, 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 = "评级日期:"; // // CreateProjectDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(567, 458); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox1); this.Name = "CreateProjectDialog"; this.Text = "新建项目"; this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox4, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.groupBox1.ResumeLayout(false); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); this.ResumeLayout(false); } /// /// 初始化数据,主要是初始化项目编号 /// private void InitializeModelData() { int num = Startup.instance.configModel.ProjectCodeNum; int addNum = 1000000 + num; String code = "P" + addNum; this.textBox2.Text = code; } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void button2_Click(object sender, EventArgs e) { //先给主model赋值 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; //进行各种判断 if (string.IsNullOrEmpty(model.itemNumber)) { MessageBox.Show(PdnResources.GetString("Menu.leaseentertheprojectnumb.Text")); return; } //给下方list赋值 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); } } //写入到数据库,判断编号是否重复 mic_project temp = mic_project_BLL.FindItenByNameAndParentId(model.itemNumber, this.parentId); if(temp!=null) { MessageBox.Show("已经存在同名项目或文件夹"); return; } //添加到数据库 mic_project project = new mic_project(); project.parent_id = this.parentId; project.project_name = model.itemNumber; //project.project_path = newPath; project.project_type = 4; mic_project_BLL.Add(project); mic_project_info info = new mic_project_info(); info.project_code = model.itemNumber; info.project_company = model.inspectionDepartment; info.project_contact = model.contact; info.project_date = model.inspectionDate; info.project_id = project.id; info.project_rating = model.ratingDate; info.project_sender = model.inspectionPerson; mic_project_info_BLL.Add(info); if (model.otherList!=null && model.otherList.Count>0) { foreach (OthersInfo child in model.otherList) { mic_project_info_item item = new mic_project_info_item(); item.info_id = info.id; item.item_key = child.name; item.item_value = child.content; mic_project_info_item_BLL.Add(item); } } //增加项目编号,到配置文件 Startup.instance.configModel.ProjectCodeNum += 1; string configXml = XmlSerializeHelper.XmlSerialize(Startup.instance.configModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create); //调用父窗口方法,进行文件夹创建 this.pdnBaseForm.CreateProjectName(model, project.id); } /// /// 添加按钮-其他 /// /// /// 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 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; } } }