// This method adds a record to the yardage database. The database keeps track of yardages and types // The method also sets the yardage and the type private void AddRecord() { string style = this.catNumber; string q = ""; String s = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbPath}; Persist Security Info=False;"; connection.ConnectionString = s; connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; string railRoadPrefix = this.railroaded == true ? "RR" : ""; YardageForm yf = new YardageForm(style, this.railroaded, this.type); if (parts.Count == 0) { yf.ShowDialog(); q = $"INSERT INTO {railRoadPrefix}{this.type}Yardage (styleName, type, [whole item]) VALUES ('{style}', '{yf.type}', {yf.yardage})"; this.type = yf.type; this.yardage = yf.yardage; operationDetails += "whole item" + '=' + yf.yardage + "/\n"; } else { string augmentedStyle = ""; string queryType = ""; string queryValue = ""; string fabricType = null; double totalYardage = 0; foreach (string part in parts) { augmentedStyle = style + '(' + part + ')'; yf.Reinitialize(augmentedStyle); yf.ShowDialog(); queryType += part + ','; queryValue += yf.yardage + ", "; totalYardage += yf.yardage; fabricType = yf.type; operationDetails += part + '=' + yf.yardage + "/\n"; } this.type = fabricType; this.yardage = totalYardage; queryType = queryType.Remove(queryType.Length - 1, 1); queryValue = queryValue.Remove(queryValue.Length - 2, 2); q = $"INSERT INTO {railRoadPrefix}{this.type}Yardage (styleName, type, {queryType}) VALUES ('{style}', '{fabricType}', {queryValue})"; } command.CommandText = q; command.ExecuteNonQuery(); connection.Close(); }
private void UpdateRecord() { string style = this.catNumber; string q = ""; String s = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbPath}; Persist Security Info=False;"; connection.ConnectionString = s; connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; string railRoadPrefix = this.railroaded == true ? "RR" : ""; YardageForm yf = new YardageForm(style, this.railroaded, this.type); string fabricType = null; string augmentedStyle = ""; string queryCondition = ""; double totalYardage = 0; if (parts.Count == 0) { yf.ShowDialog(); this.type = yf.type; this.yardage = yf.yardage; q = $"UPDATE {railRoadPrefix}{this.type}Yardage SET [whole item]={yf.yardage}, type = '{yf.type}' WHERE styleName = '{style}'"; operationDetails += "whole item" + '=' + yf.yardage + "/\n"; } else { foreach (string part in parts) { augmentedStyle = style + '(' + part + ')'; yf.Reinitialize(augmentedStyle); yf.ShowDialog(); queryCondition += $"{part}={yf.yardage},"; fabricType = yf.type; totalYardage += yf.yardage; operationDetails += part + '=' + yf.yardage + "/\n"; } queryCondition = queryCondition.Remove(queryCondition.Length - 1, 1); this.type = fabricType; this.yardage = totalYardage; q = $"UPDATE {railRoadPrefix}{fabricType}Yardage SET {queryCondition} WHERE styleName='{style}'"; } command.CommandText = q; command.ExecuteNonQuery(); connection.Close(); }