private void PopulatePickTextBoxes() { subSequences = entireSequence.Split('-'); currentSequence = subSequences[sequencePos].Split(','); for (int i = 2; i < currentSequence.Length; i++) { shortCodes.Add(currentSequence[i].Substring(0, 3)); partDescriptions.Add(currentSequence[i].Substring(3)); } if (shortCodes.Count != pickNum) { Console.WriteLine("SERVER SIDE PROBLEM\nThe number of picks do not equal the number of part numbers in the database"); return; } using (SqlConnection conn = DBUtils.GetMainDBConnection()) { conn.Open(); for (int i = 0; i < pickNum; i++) { // POSSIBLE OPTIMIZATION REQUIRED dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("SELECT [Valeo Comp.] FROM ShortCodes WHERE [Short Code] = '" + shortCodes[i] + "'", conn); da.Fill(dt); // ----------------------------------- if (dt.Rows.Count != 1) { Console.WriteLine("Part number not found in database"); return; } DataRow row = dt.Rows[0]; TextBox txtReq = new TextBox(); txtReq.Name = "reqBox" + (i + 1); txtReq.Location = new Point(lbl_Req.Location.X - 6, lbl_Req.Location.Y + txtBoxY); txtReq.Size = new Size(100, 20); txtReq.Text = row["Valeo Comp."].ToString(); TextBox txtPicked = new TextBox(); txtPicked.Name = "pickedBox" + (i + 1); txtPicked.Location = new Point(lbl_picked.Location.X - 17, lbl_picked.Location.Y + txtBoxY); txtPicked.Size = new Size(100, 20); txtPicked.Text = txtPicked.Name; txtBoxY += 38; txtBoxes.Add(txtReq.Name, txtReq); txtBoxes.Add(txtPicked.Name, txtPicked); pickBoxPnl.Controls.Add(txtReq); pickBoxPnl.Controls.Add(txtPicked); } } }
private void ReadRFID() { while (isConnected) { oSignalUserEvent.WaitOne(); oSignalUserEvent.Reset(); rfidCode = S7.GetStringAt(rfidReadBuffer, 2); string[] tempArr = rfidCode.Split(','); if (!tempArr[0].Equals(string.Empty) && tempArr != null) { if (tempArr[1] != "ALIVE") { string tempStr = tempArr[1].Remove(0, 4); using (SqlConnection conn = DBUtils.GetMainDBConnection()) { conn.Open(); dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM UserDetails", conn); da.Fill(dt); } foreach (DataRow row in dt.Rows) { if (row["Card ID"].ToString().Equals(tempStr)) { if (txt_MP_UserName.InvokeRequired) { txt_MP_UserName.Invoke((MethodInvoker) delegate { txt_MP_UserName.Text = row["First Name"].ToString() + " " + row["Last Name"]; }); } else { txt_MP_UserName.Text = row["First Name"].ToString() + " " + row["Last Name"]; } if (txt_MP_AccessLvl.InvokeRequired) { txt_MP_AccessLvl.Invoke((MethodInvoker) delegate { txt_MP_AccessLvl.Text = row["Access Level"].ToString(); }); } else { txt_MP_AccessLvl.Text = row["Access Level"].ToString(); } S7.SetStringAt(userWriteBuffer, 0, 50, tempStr); S7.SetStringAt(userWriteBuffer, 52, 50, txt_MP_UserName.Text.ToString()); short temp = short.Parse(txt_MP_AccessLvl.Text); S7.SetIntAt(userWriteBuffer, 104, temp); usersClient.DBWrite(3104, 0, userWriteBuffer.Length, userWriteBuffer); } } } else { oldUserClient.DBRead(3104, 0, oldUserReadBuffer.Length, oldUserReadBuffer); if (txt_MP_UserName.InvokeRequired) { txt_MP_UserName.Invoke((MethodInvoker) delegate { txt_MP_UserName.Text = S7.GetStringAt(oldUserReadBuffer, 52); }); } else { txt_MP_UserName.Text = S7.GetStringAt(oldUserReadBuffer, 52); } if (txt_MP_AccessLvl.InvokeRequired) { txt_MP_AccessLvl.Invoke((MethodInvoker) delegate { txt_MP_AccessLvl.Text = S7.GetIntAt(oldUserReadBuffer, 104).ToString(); }); } else { txt_MP_AccessLvl.Text = S7.GetIntAt(oldUserReadBuffer, 104).ToString(); } } } else { if (txt_MP_UserName.InvokeRequired) { txt_MP_UserName.Invoke((MethodInvoker) delegate { txt_MP_UserName.Text = string.Empty; }); } else { txt_MP_UserName.Text = string.Empty; } if (txt_MP_AccessLvl.InvokeRequired) { txt_MP_AccessLvl.Invoke((MethodInvoker) delegate { txt_MP_AccessLvl.Text = string.Empty; }); } else { txt_MP_AccessLvl.Text = string.Empty; } S7.SetStringAt(userWriteBuffer, 0, 50, string.Empty); S7.SetStringAt(userWriteBuffer, 52, 50, string.Empty); S7.SetIntAt(userWriteBuffer, 104, 0); usersClient.DBWrite(3104, 0, userWriteBuffer.Length, userWriteBuffer); } hasReadRFID = false; // creates unlimited rfid reading Thread.Sleep(100); } }
private void Handshake() { while (isConnected) { oSignalTransactEvent.WaitOne(); oSignalTransactEvent.Reset(); switch (readTransactionID) { case 2: StringBuilder sb = new StringBuilder(); sb.Append(S7.GetByteAt(transactReadBuffer, 352)) .Append(S7.GetByteAt(transactReadBuffer, 353)) .Append(S7.GetByteAt(transactReadBuffer, 354)) .Append(S7.GetByteAt(transactReadBuffer, 355)) .Append(S7.GetByteAt(transactReadBuffer, 356)) .Append(S7.GetByteAt(transactReadBuffer, 357)) .Append(S7.GetByteAt(transactReadBuffer, 358)) .Append(S7.GetByteAt(transactReadBuffer, 359)); palletID = Int64.Parse(sb.ToString()); this.Invoke((MethodInvoker) delegate { skid_txt.Text = sb.ToString(); }); using (SqlConnection conn = DBUtils.GetMainDBConnection()) { conn.Open(); dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("SELECT [Pallet Number] FROM Pallets WHERE [Pallet ID] = '" + palletID + "'", conn); da.Fill(dt); } if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { palletNum = Int32.Parse(row["Pallet Number"].ToString()); UpdateUISkidID(); } S7.SetByteAt(transactWriteBuffer, 45, 99); S7.SetStringAt(transactWriteBuffer, 96, 200, ((short)palletNum).ToString()); int result1 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer); Console.WriteLine("-------------------------" + "\nTransaction ID OUT : 99" + "\nPallet ID : " + palletID + "\nResult : Found pallet in database" + "\nPLC Write Result : " + result1 + "\n-------------------------"); } else { S7.SetByteAt(transactWriteBuffer, 45, 3); S7.SetByteAt(transactWriteBuffer, 48, 99); int result2 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer); Console.WriteLine("-------------------------" + "\nTransaction ID OUT : 3" + "\nPallet ID : " + palletID + "\nResult : Did not find pallet in database" + "\nErrorcode : 99" + "\nPLC Write Result : " + result2 + "\n-------------------------"); } Thread.Sleep(50); break; case 4: case 6: case 8: string a = S7.GetStringAt(transactReadBuffer, 96).ToString(); palletNum = Int32.Parse(a); using (SqlConnection conn = DBUtils.GetMainDBConnection()) { conn.Open(); dt = new DataTable(); SqlDataAdapter da1 = new SqlDataAdapter("SELECT [Pallet Number] FROM Pallets WHERE [Pallet Number] = " + palletNum, conn); da1.Fill(dt); // If no duplicates were found if (dt.Rows.Count == 0) { SqlCommand da2 = new SqlCommand("INSERT INTO Pallets ([Pallet ID],[Pallet Number]) VALUES (@palletID,@palletNum)", conn); da2.Parameters.AddWithValue("@palletID", palletID.ToString()); da2.Parameters.AddWithValue("@palletNum", palletNum); da2.ExecuteNonQuery(); UpdateUISkidID(); S7.SetByteAt(transactWriteBuffer, 45, 99); S7.SetStringAt(transactWriteBuffer, 96, 200, palletNum.ToString()); // Confirm what needs to be written back to plc with the trID int result3 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer); Console.WriteLine("-------------------------" + "\nTransaction ID OUT : 99" + "\nPallet ID : " + palletID + "\nResult : Successfully added pallet to database" + "\nPLC Write Result : " + result3 + "\n-------------------------"); } else { S7.SetByteAt(transactWriteBuffer, 45, 5); S7.SetByteAt(transactWriteBuffer, 48, 98); int result3 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer); Console.WriteLine("-------------------------" + "\nTransaction ID OUT : 5" + "\nPallet ID : " + palletID + "\nResult : Duplicate pallet number found in database" + "\nErrorcode : 99" + "\nPLC Write Result : " + result3 + "\n-------------------------"); } } break; case 100: Console.WriteLine("-------------------------" + "\nTransaction ID OUT : " + readTransactionID + "\nResult : Handshake done... Starting next screen." + "\n-------------------------"); hub.PublishAsync(new ScreenChangeObject("2", palletNum)); this.Close(); break; default: break; } } }