public void saveData(sample_data _data) { try { sample sample = db.sample.Where(S => S.Id == _data.id_sample).FirstOrDefault(); sample.sample_data.Add(_data); db.SaveChanges(); } catch (UpdateException ex) { var a = ex.InnerException.Message.Split('\r')[0].ToString(); } }
public void update_vendor(/*vendors vendor*/) { SqlCommandBuilder scb = new SqlCommandBuilder(); sample_data sampledata = new sample_data(); vendors vendor = sampledata.get_sample_vendor(); //select the vendor being used sql_conn.ConnectionString = _db_config.inven_general_conn; DataSet ds = new DataSet(); sql_conn.Open(); SqlDataAdapter sda1 = new SqlDataAdapter("SELECT TOP(1) * FROM vendor WHERE id = " + vendor.id, sql_conn); sda1.Fill(ds, "vendor"); scb = new SqlCommandBuilder(sda1); //((System.Data.DataTable)(new System.Collections.ArrayList.ArrayListDebugView(ds.Tables.List).Items[0])).Columns.List if (ds.Tables["vendor"].Rows.Count == 1) { object[] drd = ds.Tables["vendor"].Rows[0].ItemArray; for (int i = 1; i <= drd.Count(); i++) { vendor = _switch.vendorSwitch(i, drd[i].ToString(), vendor); } SqlCommand update = scb.GetUpdateCommand(true); foreach (SqlParameter param in update.Parameters) { if (param.SourceColumn.ToString() == "id") { continue; } else { param.Value = _switch.vendorSqlSwitch(param.SourceColumn, vendor); } } update.ExecuteNonQuery(); } sql_conn.Close(); }
private void ParseBuffer() { while (Buffer.Count > 0) { // packet header available and one packet available while ((Buffer.Count > 0) && (Buffer[0] != 0xa5)) { Buffer.RemoveAt(0); } if ((Buffer.Count >= 4) && (Buffer[0] == 0xa5)) { // read packet byte[] pkg = new byte[4]; Olimexino328_packet pk = new Olimexino328_packet(); for (int i = 0; i < 4; i++) { pkg[i] = Buffer[0]; Buffer.RemoveAt(0); } if ((pkg[0] == 0xa5) && (pkg[1] == 0x5a)) { if ((pkg[2] == 0xFF) && (pkg[3] == 0xFF)) { termina = true; } //serialPort1.Close(); else { pk.sync0 = pkg[0]; pk.sync1 = pkg[1]; pk.d1 = (UInt16)(pkg[3] + (pkg[2] << 8)); sample_data aux_item = new sample_data(); aux_item.id_sample = id_dample; aux_item.A0 = pk.d1;//*U; aux_item.order = SampleDataList.Count() + 1; aux_item.olimex_count = pk.count; //BL.saveData(aux_item); SampleDataList.Add(aux_item); //Debug.WriteLine("-------------------"); //Debug.WriteLine(pk.d1); //Debug.WriteLine(pkg[1]); //Debug.WriteLine(pkg[2]); //Debug.WriteLine(pkg[3]); //Debug.WriteLine(pkg[4]); //Debug.WriteLine(pkg[5]); //Debug.WriteLine(pkg[6]); //Debug.WriteLine((UInt16)(pkg[5] + (pkg[4] << 8))); //Debug.WriteLine(SampleDataList.Count()); } } else { Debug.WriteLine("Invalid packet received!"); MessageBox.Show("Invalid packet received!"); } } else { break; } } }