/*-------------------------------------------------------------*/ private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbxMPN.Text)) { MessageBox.Show("Please enter a valid manufacturer part number", "Error: invalid manufacturer part number", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (tbxMPN.Text.Contains(',')) { MessageBox.Show("manufacturer part number contains a ','" + Environment.NewLine + "this is not allowed.", "Error: Comma not allowed", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { //Generate new footprint string manufacturerPartNumber = tbxMPN.Text; float width = (float)nudWidth.Value; float length = (float)nudLength.Value; float height = (float)nudHeight.Value; int rotation = Convert.ToInt32(nudRotation.Value); float offsetX = (float)bscOffset.ValueX; float offsetY = (float)bscOffset.ValueY; float feedRate = (float)nudFeedRate.Value; StackType stackType = PNPconverterTools.StringToStackType(cbxStackType.SelectedItem.ToString()); footPrint_ = new Footprint(manufacturerPartNumber, width, length, height, rotation, offsetX, offsetY, feedRate, (Nozzle)cbxNozzle.SelectedItem, stackType); newFootprintMade_ = !DatabaseOperations.FootprintExists(footPrint_.ManufacturerPartNumber); if (newFootprintMade_) { //new footprint DatabaseOperations.AddNewFootprint(footPrint_); } else { //change of values DatabaseOperations.UpdateFootprint(footPrint_); } this.DialogResult = DialogResult.Yes; this.Close(); } catch (Exception exc) { MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Get the footprint from the database specified by the connectionstring /// </summary> /// <param name="manufacturerPartNumber">Manufacturer part number to be loaded</param> /// <param name="connectionString_">Connectionstring for the sqlite database</param> /// <returns>Footprint of the manufacturere part number</returns> private static Footprint GetFootprint(string manufacturerPartNumber, string connectionString_) { Footprint result = null; string sqlString = @"SELECT f.manufacturerPartNumber,f.width,f.length,f.height,f.rotation,f.offsetStackX,f.offsetStackY,f.feedRate,n.name as nozzle,s.name as stackType FROM footprints f, nozzles n,stackTypes s WHERE n.id = f.nozzle_id AND s.id = f.StackType_id AND f.manufacturerPartNumber = @manufacturerPartNumber"; using (SqliteConnection dbConnection = new SqliteConnection(connectionString_)) using (SqliteCommand dbCommand = new SqliteCommand(sqlString, dbConnection)) { dbConnection.Open(); dbCommand.Parameters.AddWithValue("manufacturerPartNumber", manufacturerPartNumber); using (SqliteDataReader reader = dbCommand.ExecuteReader()) { reader.Read(); if (reader.HasRows) { string partNumber_ = reader["manufacturerPartNumber"].ToString(); float width_ = float.Parse(reader["width"].ToString()); float length_ = float.Parse(reader["length"].ToString()); float height_ = float.Parse(reader["height"].ToString()); int rotation_ = Int32.Parse(reader["rotation"].ToString()); float offsetX_ = float.Parse(reader["offsetStackX"].ToString()); float offsetY_ = float.Parse(reader["offsetStackY"].ToString()); float feedRate = float.Parse(reader["feedRate"].ToString()); Nozzle nozzle = PNPconverterTools.StringToNozzle(reader["nozzle"].ToString()); StackType stackType = PNPconverterTools.StringToStackType(reader["stackType"].ToString()); result = new Footprint(partNumber_, width_, length_, height_, rotation_, offsetX_, offsetY_, feedRate, nozzle, stackType); } } dbConnection.Close(); } return(result); }