private void Form1_Load(object sender, EventArgs e) { string[] AvailableCOMPorts = System.IO.Ports.SerialPort.GetPortNames(); serialPort1.PortName = AvailableCOMPorts[0]; serialPort1.BaudRate = 9600; serialPort1.DataBits = 8; serialPort1.StopBits = System.IO.Ports.StopBits.One; serialPort1.Parity = Parity.None; string xmlFile = Application.StartupPath + "\\Setting.xml"; XmlDocument doc = new XmlDocument(); if (File.Exists(xmlFile)) { doc.Load(xmlFile); XmlNode node = doc.DocumentElement.SelectSingleNode("/Setting/SerialPort/Name"); if (node != null) { serialPort1.PortName = node.InnerText; } node = doc.DocumentElement.SelectSingleNode("/Setting/SerialPort/BaudRate"); if (node != null) { serialPort1.BaudRate = Int32.Parse(node.InnerText); } node = doc.DocumentElement.SelectSingleNode("/Setting/FilePath"); if (node != null) { _filepath = node.InnerText; } int size; node = doc.DocumentElement.SelectSingleNode("/Setting/Font"); if (node != null) { if (Int32.TryParse(node.InnerText, out size)) { DataGridView1.DefaultCellStyle.Font = new Font("Microsoft JhengHei", size); } } } Directory.CreateDirectory(_filepath); try { Sqlite.Open(); } catch (Exception ex) { EventLog.Write(ex.Message); } }
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 deleteColumnToolStripMenuItem_Click(object sender, EventArgs e) { if (SelectHeaderColumnIndex > -1) { if (stationComboBox.Text != "" && modelComboBox.Text != "" && customerComboBox.Text != "") { tableColList.RemoveAt(SelectHeaderColumnIndex); DataGridView1.Columns.RemoveAt(SelectHeaderColumnIndex); Sqlite.DeleteColumnInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, SelectHeaderColumnIndex); Sqlite.UpdateProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, DataGridView1.RowCount, DataGridView1.ColumnCount); } SelectHeaderColumnIndex = -1; } }
private void addRowToolStripMenuItem_Click(object sender, EventArgs e) { if (SelectHeaderRowIndex > -1) { DataGridView1.Rows.Insert(SelectHeaderRowIndex); for (int i = 0; i < DataGridView1.RowCount; i++) { DataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString(); } SelectHeaderRowIndex = -1; Sqlite.UpdateProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, DataGridView1.RowCount, DataGridView1.ColumnCount); } }
//-------------------------------------Product Setting------------------------------------- private void stationComboBox_GotFocus(object sender, EventArgs e) { stationComboBox.Items.Clear(); List <string> stations = new List <string>(); Sqlite.SelectAllStation(ref stations); foreach (string station in stations) { stationComboBox.Items.Add(station); } stations.Clear(); stations = null; }
private void modelComboBox_GotFocus(object sender, EventArgs e) { modelComboBox.Items.Clear(); if (stationComboBox.Text != "") { List <string> models = new List <string>(); Sqlite.SelectAllModelNum(stationComboBox.Text, ref models); foreach (string modelNum in models) { modelComboBox.Items.Add(modelNum); } models.Clear(); models = null; } }
private void customerComboBox_GotFocus(object sender, EventArgs e) { customerComboBox.Items.Clear(); if (stationComboBox.Text != "" && modelComboBox.Text != "") { List <string> customers = new List <string>(); Sqlite.SelectAllCustomer(stationComboBox.Text, modelComboBox.Text, ref customers); foreach (string customer in customers) { customerComboBox.Items.Add(customer); } customers.Clear(); customers = null; } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { tableColList.Clear(); if (serialPort1.IsOpen) { serialPort1.Close(); } try { Sqlite.Close(); } catch (Exception ex) { EventLog.Write(ex.Message); } }
private void deleteBtn_Click(object sender, EventArgs e) { if (DataGridView1.CurrentCell == null) { MessageBox.Show("请选择表格", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (stationComboBox.Text == "") { MessageBox.Show("请输入站別", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (modelComboBox.Text == "") { MessageBox.Show("请输入产品型号", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (customerComboBox.Text == "") { MessageBox.Show("请输入客戶別", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (MessageBox.Show("确定删除表格啊?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Sqlite.DeleteProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text); for (int i = 0; i < tableColList.Count; i++) { Sqlite.DeleteColumnInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, i); } DataGridView1.Rows.Clear(); DataGridView1.Columns.Clear(); stationComboBox.Text = ""; modelComboBox.Text = ""; customerComboBox.Text = ""; } }
private void DataGridView1_ColumnHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { 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; Sqlite.UpdateColumnsInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, e.ColumnIndex, tableCol); DataGridView1.Columns[e.ColumnIndex].Name = tableCol.Name; int size = Convert.ToInt32(DataGridView1.DefaultCellStyle.Font.Size); if (tableCol.Readvalue == 4) { DataGridView1.Columns[e.ColumnIndex].Width = size * 10; } else { DataGridView1.Columns[e.ColumnIndex].Width = size * 6; } } DataGridView1.Columns[e.ColumnIndex].HeaderCell.Style.BackColor = SystemColors.Control; }
private void saveDataToDB() { string result = ""; for (int i = 0; i < DataGridView1.Rows.Count; i++) { for (int j = 0; j < DataGridView1.Columns.Count; j++) { result += DataGridView1[j, i].FormattedValue.ToString(); if (j == DataGridView1.Columns.Count - 1) { result += "\r\n"; } else { result += ","; } } } Sqlite.InsertData(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, result, string.Format("{0:yyyy/MM/dd HH:mm:ss}", DateTime.Now)); }
private void customerComboBox_KeyPress(object sender, KeyPressEventArgs e) { TABLECOLUMN tableCol; if (e.KeyChar == (Char)13) { if (stationComboBox.Text != "" && modelComboBox.Text != "" && customerComboBox.Text != "") { if (Sqlite.SelectProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text) == 1) { return; } tableColList.Clear(); DataGridView1.Rows.Clear(); DataGridView1.Columns.Clear(); DataGridView1.ColumnCount = 10; int size = Convert.ToInt32(DataGridView1.DefaultCellStyle.Font.Size); for (int i = 0; i < DataGridView1.ColumnCount; i++) { DataGridView1.Columns[i].Width = size * 6; 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].Height = size + 15; DataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString(); } DataGridView1.CurrentCell.Selected = false; int rows = DataGridView1.Rows.Count; int columns = DataGridView1.Columns.Count; Sqlite.InsertProduct(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, rows, columns); for (int i = 0; i < tableColList.Count; i++) { tableCol = tableColList[i]; Sqlite.InsertColumnInfo(stationComboBox.Text, modelComboBox.Text, customerComboBox.Text, i, tableCol); } this.ActiveControl = DataGridView1; } } else { if (!LoginForm.Login) { e.Handled = true; } } }