/// <summary> /// Receive tag information function /// </summary> /// <param name="receivedAntennaDetails">Struct for storing tag information</param> /// <returns></returns> public int receivedTagInfo(ref AntennaDetails revMsg) { byte sLength = 255; // string sData = ""; byte[] btData = new byte[255]; int bResult = 0; try { switch (SAAT_CODE_TYPE) { case 0: bResult = RFIDAPI.SAAT_6CRevEPCMsg(pHandle, out sAntenna, btData, out sLength); break; case 1: bResult = RFIDAPI.SAAT_6CRevTIDMsg(pHandle, out sAntenna, btData, out sLength); break; case 2: bResult = RFIDAPI.SAAT_6BRevUIDMsg(pHandle, out sAntenna, btData, out sLength); break; } } catch { } if (bResult == 1 && sLength != 255) { //MessageBox.Show("" + sAntenna); revMsg.antennaNo = (int)sAntenna; for (byte bytei = 0; bytei < sLength; bytei++) sData += btData[bytei].ToString("X2"); revMsg.epcCode = sData; revMsg.nRepeatTime = 1; // MessageBox.Show("" + revMsg.nRepeatTime); } if (revMsg.antennaNo == 1 && revMsg.nRepeatTime == 1) { revMsg.nRepeatTime = revMsg.nRepeatTime - 1; WMScontext wms = new WMScontext(); FinishedProduct fp = new FinishedProduct { DateManufactured = DateTime.Now, Status = (Status)Enum.Parse(typeof(Status),"Stored"), EPC = sData }; wms.FinishedProducts.Add(fp); wms.SaveChanges(); //try //{ // string MyConnectionString = "Server=localhost;Database=rfid_warehouse_management_system;uid=root;password=;"; // MySqlConnection connection = new MySqlConnection(MyConnectionString); // connection.Open(); // MySqlCommand logincmd = connection.CreateCommand(); // logincmd.CommandText = "SELECT count(epc) from `finished_product` where epc=@epc"; // logincmd.Parameters.AddWithValue("@epc", sData); // int logincount = Convert.ToInt32(logincmd.ExecuteScalar()); // DateTime dT = new DateTime(); // dT = DateTime.Now; // string status = "stored"; // if (logincount == 0) // { // MySqlCommand insertcmd = connection.CreateCommand(); // insertcmd.CommandText = "INSERT INTO `finished_product` (epc, date_manufactured, status, id_manufacturer_has_production_line) values(@epc, @date_manufactured, @status, @id_manufacturer_has_production_line);"; // insertcmd.Parameters.AddWithValue("@epc", sData); // insertcmd.Parameters.AddWithValue("@date_manufactured", dT); // insertcmd.Parameters.AddWithValue("@status", status); // insertcmd.Parameters.AddWithValue("@id_manufacturer_has_production_line", 18); // insertcmd.ExecuteNonQuery(); // MySqlCommand displaycmd = connection.CreateCommand(); // displaycmd.CommandText = "SELECT finished_product.epc AS `RFID`, finished_product.date_manufactured AS `Manufactured`, finished_product.status AS `Status`, manufacturer_has_production_line.production_line_no AS `Production Line No.`, manufacturer_has_production_line.id_product FROM finished_product INNER JOIN manufacturer_has_production_line ON finished_product.id_manufacturer_has_production_line = manufacturer_has_production_line.id_manufacturer_has_production_line;"; // MySqlDataAdapter rfidadap = new MySqlDataAdapter(displaycmd); // DataSet rfidds = new DataSet(); // rfidadap.Fill(rfidds); // //dataGridRFID.DataSource = rfidds.Tables[0].DefaultView; // connection.Close(); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} } if (revMsg.antennaNo == 2 && revMsg.nRepeatTime == 1) { revMsg.nRepeatTime = revMsg.nRepeatTime - 1; WMScontext wms = new WMScontext(); FinishedProduct fp = new FinishedProduct { DateManufactured = DateTime.Now, Status = (Status)Enum.Parse(typeof(Status), "OntheMove"), EPC = sData }; wms.FinishedProducts.Add(fp); wms.SaveChanges(); //try //{ // string MyConnectionString = "Server=localhost;Database=rfid_warehouse_management_system;uid=root;password=;"; // MySqlConnection connection = new MySqlConnection(MyConnectionString); // connection.Open(); // MySqlCommand logincmd = connection.CreateCommand(); // logincmd.CommandText = "SELECT count(epc) from `finished_product` where epc=@epc"; // logincmd.Parameters.AddWithValue("@epc", sData); // int logincount = Convert.ToInt32(logincmd.ExecuteScalar()); // DateTime dT = new DateTime(); // dT = DateTime.Now; // string status = "stored"; // if (logincount == 0) // { // MySqlCommand insertcmd = connection.CreateCommand(); // insertcmd.CommandText = "INSERT INTO `finished_product` (epc, date_manufactured, status, id_manufacturer_has_production_line) values(@epc, @date_manufactured, @status, @id_manufacturer_has_production_line);"; // insertcmd.Parameters.AddWithValue("@epc", sData); // insertcmd.Parameters.AddWithValue("@date_manufactured", dT); // insertcmd.Parameters.AddWithValue("@status", status); // insertcmd.Parameters.AddWithValue("@id_manufacturer_has_production_line", 19); // insertcmd.ExecuteNonQuery(); // MySqlCommand displaycmd = connection.CreateCommand(); // displaycmd.CommandText = "SELECT finished_product.epc AS `RFID`, finished_product.date_manufactured AS `Manufactured`, finished_product.status AS `Status`, manufacturer_has_production_line.production_line_no AS `Production Line No.`, manufacturer_has_production_line.id_product FROM finished_product INNER JOIN manufacturer_has_production_line ON finished_product.id_manufacturer_has_production_line = manufacturer_has_production_line.id_manufacturer_has_production_line;"; // MySqlDataAdapter rfidadap = new MySqlDataAdapter(displaycmd); // DataSet rfidds = new DataSet(); // rfidadap.Fill(rfidds); // //dataGridRFID.DataSource = rfidds.Tables[0].DefaultView; // connection.Close(); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} } return bResult; }
/// <summary> /// Receive tag information function /// </summary> /// <param name="receivedAntennaDetails">Struct for storing tag information</param> /// <returns></returns> public int receivedTagInfo(ref AntennaDetails revMsg) { byte sLength = 255; // string sData = ""; byte[] btData = new byte[255]; int bResult = 0; try { switch (SAAT_CODE_TYPE) { case 0: bResult = RFIDAPI.SAAT_6CRevEPCMsg(pHandle, out sAntenna, btData, out sLength); break; case 1: bResult = RFIDAPI.SAAT_6CRevTIDMsg(pHandle, out sAntenna, btData, out sLength); break; case 2: bResult = RFIDAPI.SAAT_6BRevUIDMsg(pHandle, out sAntenna, btData, out sLength); break; } } catch { } if (bResult == 1 && sLength != 255) { //MessageBox.Show("" + sAntenna); revMsg.antennaNo = (int)sAntenna; for (byte bytei = 0; bytei < sLength; bytei++) sData += btData[bytei].ToString("X2"); revMsg.epcCode = sData; revMsg.nRepeatTime = 1; // MessageBox.Show("" + revMsg.nRepeatTime); } if (revMsg.antennaNo == 1 && revMsg.nRepeatTime == 1) { revMsg.nRepeatTime = revMsg.nRepeatTime - 1; WMScontext wms1 = new WMScontext(); var epcCount = (from epc in wms1.FinishedProducts where epc.EPC == sData select epc).Count(); if (epcCount == 0) { FinishedProduct fp1 = new FinishedProduct { DateManufactured = DateTime.Now, Status = (Status)Enum.Parse(typeof(Status), "OntheMove"), EPC = sData }; wms1.FinishedProducts.Add(fp1); wms1.SaveChanges(); } } if (revMsg.antennaNo == 2 && revMsg.nRepeatTime == 1) { revMsg.nRepeatTime = revMsg.nRepeatTime - 1; WMScontext wms = new WMScontext(); var epcCount = (from epc in wms.FinishedProducts where epc.EPC == sData select epc).Count(); if (epcCount == 0) { FinishedProduct fp = new FinishedProduct { DateManufactured = DateTime.Now, Status = (Status)Enum.Parse(typeof(Status), "Stored"), EPC = sData }; wms.FinishedProducts.Add(fp); wms.SaveChanges(); } } return bResult; }