public static void SelectColumnsInfo(string station, string model_number, string customer, ref List <TABLECOLUMN> tableColList) { TABLECOLUMN tableCol; sqlite_cmd = sqlite_connect.CreateCommand();//create command sqlite_cmd.CommandText = "SELECT name, formula, min, max, readvalue FROM " + COLUMNSINFO_TBL_NAME + " WHERE station='" + station + "' AND model_number='" + model_number + "' AND customer='" + customer + "' ORDER BY column"; sqlite_cmd.ExecuteNonQuery(); using (SQLiteDataReader rdr = sqlite_cmd.ExecuteReader()) { while (rdr.Read()) { double min, max; tableCol = new TABLECOLUMN(); tableCol.Name = rdr.GetString(0); tableCol.Formula = rdr.GetString(1); if (Double.TryParse(rdr.GetString(2), out min)) { tableCol.Min = min; } if (Double.TryParse(rdr.GetString(3), out max)) { tableCol.Max = max; } tableCol.Readvalue = rdr.GetInt32(4); tableColList.Add(tableCol); } } }
private void customerComboBox_KeyPress(object sender, KeyPressEventArgs e) { TABLECOLUMN tableCol; if (e.KeyChar == (Char)13) { if (stationComboBox.Text != "" && modelComboBox.Text != "" && customerComboBox.Text != "") { if (TableXml.SelectProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text) == 1) { return; } tableColList.Clear(); DataGridView1.Rows.Clear(); DataGridView1.Columns.Clear(); DataGridView1.ColumnCount = 10; for (int i = 0; i < DataGridView1.ColumnCount; i++) { DataGridView1.Columns[i].Width = 60; DataGridView1.Columns[i].Name = Convert.ToChar(i + 65).ToString(); DataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; tableCol = new TABLECOLUMN(); tableCol.Name = DataGridView1.Columns[i].Name; tableColList.Add(tableCol); } for (int i = 0; i < 20; i++) { DataGridView1.Rows.Add(""); DataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString(); } DataGridView1.CurrentCell.Selected = false; int rows = DataGridView1.Rows.Count; int columns = DataGridView1.Columns.Count; TableXml.InsertProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, rows, columns); for (int i = 0; i < tableColList.Count; i++) { tableCol = tableColList[i]; TableXml.InsertColumnInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, i, tableCol); } this.ActiveControl = DataGridView1; } } else { if (!LoginForm.Login) { e.Handled = true; } } }
private void addColumnToolStripMenuItem_Click(object sender, EventArgs e) { if (SelectHeaderColumnIndex > -1) { if (stationComboBox.Text != "" && modelComboBox.Text != "" && customerComboBox.Text != "") { TABLECOLUMN tableCol = new TABLECOLUMN(); tableCol.Name = "New"; DataGridViewColumn dtCol = new DataGridViewColumn(); dtCol.Name = "New"; dtCol.Width = 60; dtCol.SortMode = DataGridViewColumnSortMode.NotSortable; dtCol.CellTemplate = new DataGridViewTextBoxCell(); DataGridView1.Columns.Insert(SelectHeaderColumnIndex, dtCol); tableColList.Insert(SelectHeaderColumnIndex, tableCol); Sqlite.InsertColumnInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, SelectHeaderColumnIndex, tableCol); Sqlite.UpdateProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, DataGridView1.RowCount, DataGridView1.ColumnCount); } SelectHeaderColumnIndex = -1; } }
private void customerComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (stationComboBox.Text != "" && modelComboBox.Text != "") { int rows = 0; int columns = 0; TABLECOLUMN tableCol; tableColList.Clear(); DataGridView1.Rows.Clear(); DataGridView1.Columns.Clear(); Sqlite.SelectColumnsInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, ref tableColList); Sqlite.SelectRowsColumns(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, ref rows, ref columns); DataGridView1.ColumnCount = columns; int size = Convert.ToInt32(DataGridView1.DefaultCellStyle.Font.Size); for (int i = 0; i < columns; i++) { if (i < tableColList.Count) { tableCol = tableColList[i]; } else { tableCol = new TABLECOLUMN(); tableColList.Add(tableCol); } if (tableCol.Readvalue == 4) { DataGridView1.Columns[i].Width = size * 10; } else { DataGridView1.Columns[i].Width = size * 6; } DataGridView1.Columns[i].Name = tableCol.Name; DataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } for (int i = 0; i < rows; i++) { string[] row = new string[columns]; DataGridView1.Rows.Add(row); DataGridView1.Rows[i].Height = size + 15; DataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString(); } this.ActiveControl = DataGridView1; } }
private void customerComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (stationComboBox.Text != "" && modelComboBox.Text != "") { int rows = 0; int columns = 0; TABLECOLUMN tableCol; tableColList.Clear(); DataGridView1.Rows.Clear(); DataGridView1.Columns.Clear(); TableXml.GetProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, ref rows, ref columns, ref tableColList); DataGridView1.ColumnCount = columns; for (int i = 0; i < columns; i++) { if (i < tableColList.Count) { tableCol = tableColList[i]; } else { tableCol = new TABLECOLUMN(); tableColList.Add(tableCol); } if (tableCol.Readvalue == 4) { DataGridView1.Columns[i].Width = 100; } else { DataGridView1.Columns[i].Width = 60; } DataGridView1.Columns[i].Name = tableCol.Name; DataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } for (int i = 0; i < rows; i++) { string[] row = new string[columns]; DataGridView1.Rows.Add(row); DataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString(); } readBtn.Enabled = true; this.ActiveControl = DataGridView1; } }
private void DataGridView1_ColumnHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (!LoginForm.Login) { return; } var cellRectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); TABLECOLUMN tableCol = tableColList[e.ColumnIndex]; DataGridView1.Columns[e.ColumnIndex].HeaderCell.Style.BackColor = Color.FromArgb(72, 180, 225); int locationX = this.Location.X + DataGridView1.Location.X + cellRectangle.Location.X + 5; int locationY = this.Location.Y + DataGridView1.Location.Y + cellRectangle.Location.Y + cellRectangle.Height + 30; ColumnForm form = new ColumnForm(e.ColumnIndex, locationX, locationY, tableCol); if (form.ShowDialog(this) == DialogResult.OK) { tableCol.Name = form.ReturnName; tableCol.Formula = form.ReturnFormula; tableCol.Min = form.ReturnMin; tableCol.Max = form.ReturnMax; tableCol.Readvalue = form.ReturnReadvalue; tableColList[e.ColumnIndex] = tableCol; TableXml.SaveColumnInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, e.ColumnIndex, tableCol); DataGridView1.Columns[e.ColumnIndex].Name = tableCol.Name; if (tableCol.Readvalue == 4) { DataGridView1.Columns[e.ColumnIndex].Width = 100; } else { DataGridView1.Columns[e.ColumnIndex].Width = 60; } } DataGridView1.Columns[e.ColumnIndex].HeaderCell.Style.BackColor = SystemColors.Control; }
public static void UpdateColumnsInfo(string station, string model_number, string customer, int column, TABLECOLUMN tableCol) { sqlite_cmd = sqlite_connect.CreateCommand();//create command sqlite_cmd.CommandText = ("UPDATE " + COLUMNSINFO_TBL_NAME + " SET name='" + tableCol.Name + "', formula='" + tableCol.Formula + "', min='" + tableCol.Min + "', max='" + tableCol.Max + "', readvalue='" + tableCol.Readvalue + "' WHERE model_number ='" + model_number + "' AND customer='" + customer + "' AND station='" + station + "' AND column='" + column + "'"); sqlite_cmd.ExecuteNonQuery(); }
//----------------------------Columns Info Table---------------------------- public static void InsertColumnInfo(string station, string model_number, string customer, int column, TABLECOLUMN tableCol) { sqlite_cmd = sqlite_connect.CreateCommand();//create command sqlite_cmd.CommandText = "INSERT INTO " + COLUMNSINFO_TBL_NAME + " VALUES ('" + station + "','" + model_number + "','" + customer + "','" + column + "','" + tableCol.Name + "','" + tableCol.Formula + "','" + tableCol.Min + "','" + tableCol.Max + "','" + tableCol.Readvalue + "');"; sqlite_cmd.ExecuteNonQuery(); }
public ColumnForm(int column, int x, int y, TABLECOLUMN tableCol) { InitializeComponent(); columnLabel.Text = string.Format("{0}列", Convert.ToChar(column + 65).ToString()); nameTextBox.Text = Convert.ToChar(column + 65).ToString(); if (tableCol != null) { formulaTextBox.Text = tableCol.Formula; minTextBox.Text = tableCol.Min.ToString("f3"); maxTextBox.Text = tableCol.Max.ToString("f3"); if (tableCol.Name != "") { nameTextBox.Text = tableCol.Name; } switch (tableCol.Readvalue) { case 0: radioButton1.Checked = true; break; case 1: radioButton2.Checked = true; break; case 2: radioButton3.Checked = true; break; case 3: radioButton4.Checked = true; break; case 4: radioButton5.Checked = true; break; } if (formulaTextBox.Text == "") { radioButton1.Visible = true; radioButton2.Visible = true; radioButton3.Visible = true; radioButton4.Visible = true; radioButton5.Visible = true; } else { radioButton1.Visible = false; radioButton2.Visible = false; radioButton3.Visible = false; radioButton4.Visible = false; radioButton5.Visible = false; } } OKBtn.BackColor = Color.FromArgb(72, 180, 225); cancelBtn.BackColor = Color.FromArgb(72, 180, 225); if ((x + this.Width) > Screen.PrimaryScreen.Bounds.Width) { x = x - ((x + this.Width) - Screen.PrimaryScreen.Bounds.Width); } this.Location = new Point(x, y); this.BackColor = Color.FromArgb(226, 226, 226); }
//-------------------------------------Other------------------------------------- private string GetValue(int column, int row) { double value = 0.0; TABLECOLUMN tableCol = tableColList[column]; if (tableCol == null) { EventLog.Write("Not found TableCol"); return(value.ToString("f3")); } try { Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics graphics = Graphics.FromImage(printscreen as Image); int w = printscreen.Size.Width; int h = printscreen.Size.Height; graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size); printscreen.Save("D:\\PrintScreen.bmp", System.Drawing.Imaging.ImageFormat.Bmp); // Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit. System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c microscope.exe D:\\PrintScreen.bmp"); procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo = procStartInfo; proc.Start(); proc.StandardOutput.ReadToEnd(); } catch (Exception ex) { EventLog.Write(ex.Message); } finally { if (File.Exists("D:\\PrintScreen.bmp")) { File.Delete("D:\\PrintScreen.bmp"); } if (File.Exists("D:\\PrintScreen.txt")) { string line; int index = 0; StreamReader file = new StreamReader("D:\\PrintScreen.txt"); while ((line = file.ReadLine()) != null) { if (tableCol.Readvalue == index) { Double.TryParse(line.Trim('-'), out value); break; } index++; } file.Close(); File.Delete("D:\\PrintScreen.txt"); } } if (value < tableCol.Min || value > tableCol.Max) { DataGridView1[column, row].Style.ForeColor = Color.Red; } else { DataGridView1[column, row].Style.ForeColor = Color.Black; } return(value.ToString("f3")); }
//-------------------------------------Other------------------------------------- private string GetValue(string readline, int column, int row) { TABLECOLUMN tableCol = tableColList[column]; double value = 0.0; double valueX = 0.0; double valueY = 0.0; double valueZ = 0.0; string alpha = ""; string result = "0.0"; if (serialPort1.BaudRate == 9600) { string[] lines = readline.Split('Y'); if (lines.Length >= 2) { Double.TryParse(Regex.Replace(lines[0].Trim(), "[^0-9.]", ""), out valueX); lines = lines[1].Split('Q'); Double.TryParse(Regex.Replace(lines[0].Trim(), "[^0-9.]", ""), out valueY); result = valueX.ToString("f3"); if (tableCol != null) { switch (tableCol.Readvalue) { case 0: //read x value = valueX; break; case 1: //read y value = valueY; break; case 4: //read alpha alpha = lines[1].Trim('-'); result = alpha; break; } } } } else { string[] lines = readline.Split(','); if (lines.Length >= 3) { Double.TryParse(Regex.Replace(lines[0].Trim(), "[^0-9.]", ""), out valueX); Double.TryParse(Regex.Replace(lines[1].Trim(), "[^0-9.]", ""), out valueY); Double.TryParse(Regex.Replace(lines[2].Trim(), "[^0-9.]", ""), out valueZ); result = valueX.ToString("f3"); if (tableCol != null) { switch (tableCol.Readvalue) { case 0: //read x value = valueX; break; case 1: //read y value = valueY; break; case 2: //read alpha value = valueZ; break; } } } } if (tableCol != null && alpha == "") { result = value.ToString("f3"); if (value < tableCol.Min || value > tableCol.Max) { DataGridView1[column, row].Style.ForeColor = Color.Red; } else { DataGridView1[column, row].Style.ForeColor = Color.Black; } } return(result); }
public static void SaveColumnInfo(string station, string model, string customer, int column, TABLECOLUMN tableCol) { int value; XmlNode child; XmlNodeList nodeList = _doc.DocumentElement.SelectNodes("/Tables/Products/Station/Model/Customer/column"); for (int i = 0; i < nodeList.Count; i++) { string great_grandparent = nodeList[i].ParentNode.ParentNode.ParentNode.FirstChild.InnerText.Trim(); string grandparent = nodeList[i].ParentNode.ParentNode.FirstChild.InnerText.Trim(); string parent = nodeList[i].ParentNode.FirstChild.InnerText.Trim(); if (great_grandparent.CompareTo(station) == 0 && grandparent.CompareTo(model) == 0 && parent.CompareTo(customer) == 0) { child = nodeList[i].FirstChild; Int32.TryParse(child.InnerText.Trim(), out value); if (value == column) { child = child.NextSibling; while (child != null) { if (child.Name.CompareTo("name") == 0) { child.InnerText = tableCol.Name; } else if (child.Name.CompareTo("formula") == 0) { child.InnerText = tableCol.Formula; } else if (child.Name.CompareTo("min") == 0) { child.InnerText = tableCol.Min.ToString("#0.00"); } else if (child.Name.CompareTo("max") == 0) { child.InnerText = tableCol.Max.ToString("#0.00"); } else if (child.Name.CompareTo("readvalue") == 0) { child.InnerText = tableCol.Readvalue.ToString(); } child = child.NextSibling; } break; } } } _doc.Save(_xmlFile); }
public static void InsertColumnInfo(string station, string model, string customer, int column, TABLECOLUMN tableCol) { XmlNode tabColNode, nameNode, formulaNode, minNode, maxNode, readvalueNode; XmlNodeList nodeList = _doc.DocumentElement.SelectNodes("/Tables/Products/Station/Model/Customer"); for (int i = 0; i < nodeList.Count; i++) { string grandparent = nodeList[i].ParentNode.ParentNode.FirstChild.InnerText.Trim(); string parent = nodeList[i].ParentNode.FirstChild.InnerText.Trim(); string current = nodeList[i].FirstChild.InnerText.Trim(); if (grandparent.CompareTo(station) == 0 && parent.CompareTo(model) == 0 && current.CompareTo(customer) == 0) { tabColNode = _doc.CreateElement("column"); tabColNode.AppendChild(_doc.CreateTextNode(column.ToString())); nameNode = _doc.CreateElement("name"); nameNode.AppendChild(_doc.CreateTextNode(tableCol.Name)); formulaNode = _doc.CreateElement("formula"); formulaNode.AppendChild(_doc.CreateTextNode(tableCol.Formula)); minNode = _doc.CreateElement("min"); minNode.AppendChild(_doc.CreateTextNode(tableCol.Min.ToString())); maxNode = _doc.CreateElement("max"); maxNode.AppendChild(_doc.CreateTextNode(tableCol.Max.ToString())); readvalueNode = _doc.CreateElement("readvalue"); readvalueNode.AppendChild(_doc.CreateTextNode(tableCol.Readvalue.ToString())); tabColNode.AppendChild(nameNode); tabColNode.AppendChild(formulaNode); tabColNode.AppendChild(minNode); tabColNode.AppendChild(maxNode); tabColNode.AppendChild(readvalueNode); nodeList[i].AppendChild(tabColNode); } } _doc.Save(_xmlFile); }
public static void GetProduct(string station, string model, string customer, ref int rows, ref int columns, ref List <TABLECOLUMN> tableColList) { double min, max; int value; TABLECOLUMN tableCol; XmlNode child; XmlNodeList nodeList = _doc.DocumentElement.SelectNodes("/Tables/Products/Station/Model/Customer/Rows"); for (int i = 0; i < nodeList.Count; i++) { string great_grandparent = nodeList[i].ParentNode.ParentNode.ParentNode.FirstChild.InnerText.Trim(); string grandparent = nodeList[i].ParentNode.ParentNode.FirstChild.InnerText.Trim(); string parent = nodeList[i].ParentNode.FirstChild.InnerText.Trim(); if (great_grandparent.CompareTo(station) == 0 && grandparent.CompareTo(model) == 0 && parent.CompareTo(customer) == 0) { string name = nodeList[i].FirstChild.InnerText.Trim(); Int32.TryParse(name, out rows); break; } } nodeList = _doc.DocumentElement.SelectNodes("/Tables/Products/Station/Model/Customer/Columns"); for (int i = 0; i < nodeList.Count; i++) { string great_grandparent = nodeList[i].ParentNode.ParentNode.ParentNode.FirstChild.InnerText.Trim(); string grandparent = nodeList[i].ParentNode.ParentNode.FirstChild.InnerText.Trim(); string parent = nodeList[i].ParentNode.FirstChild.InnerText.Trim(); if (great_grandparent.CompareTo(station) == 0 && grandparent.CompareTo(model) == 0 && parent.CompareTo(customer) == 0) { string name = nodeList[i].FirstChild.InnerText.Trim(); Int32.TryParse(name, out columns); break; } } nodeList = _doc.DocumentElement.SelectNodes("/Tables/Products/Station/Model/Customer/column"); for (int i = 0; i < nodeList.Count; i++) { string great_grandparent = nodeList[i].ParentNode.ParentNode.ParentNode.FirstChild.InnerText.Trim(); string grandparent = nodeList[i].ParentNode.ParentNode.FirstChild.InnerText.Trim(); string parent = nodeList[i].ParentNode.FirstChild.InnerText.Trim(); if (great_grandparent.CompareTo(station) == 0 && grandparent.CompareTo(model) == 0 && parent.CompareTo(customer) == 0) { child = nodeList[i].FirstChild; tableCol = new TABLECOLUMN(); child = child.NextSibling; while (child != null) { if (child.Name.CompareTo("name") == 0) { tableCol.Name = child.InnerText.Trim(); } else if (child.Name.CompareTo("formula") == 0) { tableCol.Formula = child.InnerText.Trim(); } else if (child.Name.CompareTo("min") == 0) { Double.TryParse(child.InnerText.Trim(), out min); tableCol.Min = min; } else if (child.Name.CompareTo("max") == 0) { Double.TryParse(child.InnerText.Trim(), out max); tableCol.Max = max; } else if (child.Name.CompareTo("readvalue") == 0) { Int32.TryParse(child.InnerText.Trim(), out value); tableCol.Readvalue = value; } child = child.NextSibling; } tableColList.Add(tableCol); } } }