private void Insert_SQL(string Tab) { List <string> nameColumns = new List <string>(); List <string> ValueColumn = new List <string>(); List <int> indexSelect = new List <int>(); for (int i = 0; i < dtEdit.Columns.Count; i++) { nameColumns.Add(dtEdit.Columns[i].Name); } foreach (DataGridViewCell cell in dtEdit.SelectedCells) { indexSelect.Add(cell.RowIndex); //ListRowIndexMOD.Add(cell.RowIndex); } indexSelect = indexSelect.Distinct().ToList(); // float a = 12; // float a = 1.2; foreach (int selectedrowindex in indexSelect) { DataGridViewRow selectedRow = dtEdit.Rows[selectedrowindex]; ValueColumn.Clear(); foreach (string nameColumn in nameColumns) { ValueColumn.Add(Convert.ToString(selectedRow.Cells[nameColumn].Value)); // string VA } bool blcheck = true; bool blcheck1 = true; try { blcheck1 = SQLITE.CHECK("*", G.curTab, "" + nameColumns[0] + "='" + ValueColumn[0] + "'"); blcheck = SQLITE.CHECK("*", G.curTab, "" + nameColumns[1] + "='" + ValueColumn[1] + "'"); } catch (Exception) { } if (blcheck == false || blcheck1 == false) { SQLITE.Insert(Tab, ValueColumn); } else { MessageBox.Show("the same!"); } } LoadData(G.curTab); }
private void btnAdd_Click(object sender, EventArgs e) { G.sourceSQL = G.VariableSQL; if (!cSQL.CHECK("*", "DEVICE", "DEVICE='" + txtName.Text + "' OR PARAMETER ='" + cbPara.Text.Trim() + G.portIP + "'")) { if (cbPara.Text != "") { dynamic itModel = cbModel.Items[cbModel.SelectedIndex]; DBPlcId eModel = (DBPlcId)int.Parse(itModel.Value); dynamic itVia = cbVia.Items[cbVia.SelectedIndex]; Via eVia = (Via)int.Parse(itVia.Value); AxDBCommManager plcTemp = new AxDBCommManager(); // cbModel.Items plcTemp = KEYENCEs.Create(eModel, eVia, cbPara.Text.Trim() + G.portIP); // G.ListKey.Add(new ListKey("", plcTemp, isConnect.Connected, img, new Point(0, 0))); G.LisPLC.Add(new LisPLC(txtName.Text, cbCo.Text, cbModel.Text, eVia, cbPara.Text.Trim() + G.portIP, plcTemp, G.isConnect, picModel, picVia, G.pPen)); List <string> List = new List <string>(); List.Add(G.LisPLC[G.LisPLC.Count - 1].name); List.Add("PLC"); List.Add(G.LisPLC[G.LisPLC.Count - 1].Co.ToString()); List.Add(G.LisPLC[G.LisPLC.Count - 1].Mod.ToString()); List.Add(G.LisPLC[G.LisPLC.Count - 1].Via.ToString()); List.Add(G.LisPLC[G.LisPLC.Count - 1].Para.ToString()); List.Add(G.LisPLC[G.LisPLC.Count - 1].isConnect.ToString()); cSQL.Insert("DEVICE", List); // fm1.PicMap.Invalidate(); fm1.picMap.Invalidate(); // LoadDevice(); G.pPen.X += picReview.Width + 10; if (G.pPen.X + picReview.Width >= fm1.PicMap.Width) { G.pPen.Y += picReview.Height + 50; G.pPen.X = 0; } } else { MessageBox.Show("Vui lòng quét thông số kết nối trước khi thêm thiết bị mới !"); } } else { MessageBox.Show("Vui lòng đặt tên khác hoặc thông số khác !"); } G.sourceSQL = G.defautSQL; // int A = plcTemp.ReadDevice(DBPlcDevice.DKV3000_DM, "110"); }
private void btnCreateSFS_Click(object sender, EventArgs e) { // MessageBox.Show("Bạn đã tạo thành công dự án" + txtName.Text + " tại : " + Environment.NewLine + "Đường dẫn : " + txtPath.Text); DialogResult dialogResult = MessageBox.Show("Bạn muốn giữ nguyên DỮ LIỆU cũ không", "Project mới", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { G.sourceSQL = G.VariableSQL; SQLITE.DeleteAll("DEVICE"); SQLITE.DeleteAll("CycleTime"); SQLITE.DeleteAll("Global"); SQLITE.DeleteAll("LostTime"); SQLITE.DeleteAll("Yield"); G.sourceSQL = G.ToolSQL; SQLITE.DeleteAll("Quantity"); SQLITE.DeleteAll("TOOL"); SQLITE.DeleteAll("Time"); G.sourceSQL = G.ChartSQL; SQLITE.DeleteAll("CHART"); } //INSERT INTO INFOR VALUES ('0','12/09/2018','EMTY','');"; //gancau lech cmd G.sourceSQL = G.defautSQL; if (!SQLITE.CHECK("*", "INFOR", "NMAE='" + txtName.Text.Trim() + "'")) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("SELECTS", "0"); SQLITE.Update("INFOR", dic, "", G.defautSQL); System.IO.Directory.CreateDirectory(txtPath.Text + "\\" + txtName.Text + "\\"); G.pathSQL = txtPath.Text + "\\" + txtName.Text; List <string> list = new List <string>(); list.Add(DateTime.Now.ToString("dd/MM/yyyy")); list.Add(txtName.Text.Trim()); list.Add(G.pathSQL); list.Add("1"); SQLITE.Insert("INFOR", list); this.Close(); Form1 = new Form1(); Form1.btnNewDevice.Enabled = true; Form1.Text = "Program :" + txtName.Text; Form1.Show(); this.Hide(); } else { MessageBox.Show("VUI LÒNG ĐẶT TÊN KHÁC ! "); } }
public DATAHOUR(string timeBegin) { G.sourceSQL = G.VariableSQL; string datenows = DateTime.Now.ToString("yyyy-MM-dd"); foreach (ListVariables ListVariables in G.ListVariables) { List <string> list = new List <string>(); string nameVariable = ""; int iShift = G.Shift + 1; if (ListVariables.Name != null) { nameVariable = ListVariables.Name; } else if (ListVariables.CycleTime != null) { nameVariable = ListVariables.CycleTime.Name; } else if (ListVariables.Yield != null) { nameVariable = ListVariables.Yield.Name; } else if (ListVariables.LostTime != null) { nameVariable = ListVariables.LostTime.Name; } if (!SQLITE.CHECK("*", "DATEHOUR", "DATE='" + datenows + "' AND SHIFT ='" + iShift + "' AND HOUR ='" + timeBegin + "' AND VARIABLE ='" + nameVariable + "'")) { list.Add(datenows); list.Add(iShift + ""); list.Add(timeBegin); list.Add(nameVariable + ""); list.Add(ListVariables.Val + ""); SQLITE.Insert("DATEHOUR", list); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("VALUE", ListVariables.Val + ""); SQLITE.Update("DATEHOUR", dic, "DATE='" + datenows + "' AND SHIFT ='" + iShift + "' AND HOUR ='" + timeBegin + "' AND VARIABLE ='" + nameVariable + "'", G.VariableSQL); } } }
private void btnAddVari_Click(object sender, EventArgs e) { G.sourceSQL = G.VariableSQL; if (typeVariable == typeVariable2.CycleTime) { { if (!cSQL.CHECK("*", "CycleTime", "NAME='" + txtNameVari.Text.Trim() + "' ")) { DateTime dt = new DateTime(); List <Point> pDrawing = new List <Point>(); G.ListVariables.Add(new ListVariables(new CycleTime(txtNameNew.Text, G.ListVariables[txtNameVari.SelectedIndex], "0", 0, Convert.ToInt32(numScan_change_V.Value), dt, dt, isCycle.open, false), typeVariable2.CycleTime)); List <string> List = new List <string>(); List.Add(txtNameNew.Text); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.ListVariables.Name); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.cycleTime); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.tempValue + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.numScan + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.dtBegin + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.dtEnd + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.isCycle.ToString() + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].CycleTime.blStartCycle + ""); cSQL.Insert("CycleTime", List); LoadData("CycleTime"); } else { MessageBox.Show("Vui lòng nhập tên khác!"); } } } else if (typeVariable == typeVariable2.Global) { if (!cSQL.CHECK("*", "Global", "NAME='" + txtNameVari.Text.Trim() + "' ")) { if (!cSQL.CHECK("*", "Global", "AREA='" + cbArea.Text.Trim() + "' AND BIT ='" + txtbit.Text.Trim() + "AND DEVICE ='" + cbDevice.Text.Trim() + "'")) { //dynamic itArea = cbArea.Items[cbArea.SelectedIndex]; dynamic itTypeBit = cbTypeBit.Items[cbTypeBit.SelectedIndex]; typeBit typeBit = (typeBit)int.Parse(itTypeBit.Value); G.ListVariables.Add(new ListVariables(txtNameVari.Text, G.LisPLC[cbDevice.SelectedIndex], cbArea.Text.Trim(), txtbit.Text.Trim(), txtVal.Text, isBit._using, typeBit, typeVariable2.Global)); List <string> List = new List <string>(); List.Add(txtNameVari.Text); List.Add(G.LisPLC[cbDevice.SelectedIndex].name); List.Add(cbArea.Text.Trim()); List.Add(txtbit.Text.Trim()); List.Add(typeBit.ToString()); List.Add(txtVal.Text); List.Add(isBit._using.ToString()); cSQL.Insert("Global", List); LoadData("Global"); } else { MessageBox.Show("Vui lòng chọn Bit khác!"); } } else { MessageBox.Show("Vui lòng nhập tên khác!"); } } else if (typeVariable == typeVariable2.Yield) { if (!cSQL.CHECK("*", "Yield", "NAME='" + txtNameVari.Text.Trim() + "' ")) { // cmd.CommandText = " CREATE TABLE Yield (NAME nvachar(50),Yield nvachar(50),ListOK nvachar(50),ListNG nvachar(50));"; //gancau lech cmd // cmd.ExecuteNonQuery();//thuc thi DateTime dt = new DateTime(); List <Point> pDrawing = new List <Point>(); G.ListVariables.Add(new ListVariables(new Yield(txtNameNew.Text, "100", ListYieldOK, ListYieldNG), typeVariable2.Yield)); List <string> List = new List <string>(); string ListOKsql = "", ListNGsql = ""; foreach (ListVariables s in ListYieldOK) { ListOKsql += s.Name + ","; } ListOKsql = ListOKsql.Substring(0, ListOKsql.Count() - 1); foreach (ListVariables s in ListYieldNG) { ListNGsql += s.Name + ","; } ListNGsql = ListNGsql.Substring(0, ListNGsql.Count() - 1); List.Add(txtNameNew.Text); List.Add(G.ListVariables[G.ListVariables.Count - 1].Yield.valYield); List.Add(ListOKsql); List.Add(ListNGsql); cSQL.Insert("Yield", List); LoadData("Yield"); } else { MessageBox.Show("Vui lòng nhập tên khác!"); } } else if (typeVariable == typeVariable2.LostTime) { if (!cSQL.CHECK("*", "LostTime", "NAME='" + txtNameVari.Text.Trim() + "' ")) { DateTime dt = new DateTime(); List <Point> pDrawing = new List <Point>(); //(new LostTime(txtNameNew.Text, G.ListVariables[txtNameVari.SelectedIndex], "0", 0, Convert.ToInt32(numScan_change_V.Value), dt, dt, isLost.open, false), typeVariable.LosTime) G.ListVariables.Add(new ListVariables(new LostTime(txtNameNew.Text, G.ListVariables[txtNameVari.SelectedIndex], "0", 0, Convert.ToInt32(numScan_change_V.Value), dt, dt, isLost.open, false), typeVariable2.LostTime)); List <string> List = new List <string>(); List.Add(txtNameNew.Text); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.ListVariables.Name); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.LostTimes); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.tempValue + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.timeMax + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.dtBegin + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.dtEnd + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.isLost.ToString() + ""); List.Add(G.ListVariables[G.ListVariables.Count - 1].LostTime.blStart + ""); cSQL.Insert("LostTime", List); LoadData("LostTime"); } else { MessageBox.Show("Vui lòng nhập tên khác!"); } } }