public List <IDataModel> GroupBy(GroupRows groupName) { string switchVar = ""; switch (groupName) { case GroupRows.Surname: switchVar = "SURNAME"; break; case GroupRows.Date: switchVar = "DateOfCall"; break; case GroupRows.Cost: switchVar = "Cost"; break; } List <IDataModel> selections = new List <IDataModel>(); connection.Open(); string ReqText = $"SELECT * FROM {tableName} ORDER BY {switchVar}"; OleDbCommand getReq = new OleDbCommand(ReqText, connection); OleDbDataReader reader = getReq.ExecuteReader(); while (reader.Read()) { IntercitySelection model = new IntercitySelection((double)(reader[1]), (DateTime)reader[2], (string)reader[3]); selections.Add(model); } connection.Close(); return(selections); }
public List <IDataModel> CreateNewSelection(DateTime start, DateTime end) { var Tcount = GetTablesCount(); tableName = $"Selection{Tcount}"; var createReq = $"CREATE TABLE {tableName} " + $"(Code COUNTER CONSTRAINT PrimaryKey PRIMARY KEY," + $"Cost DOUBLE," + $"DateOfCall DATETIME," + $"SURNAME VARCHAR)"; connection.Open(); OleDbCommand Reqest = new OleDbCommand(createReq, connection); Reqest.ExecuteNonQuery(); connection.Close(); var Ranged = GetRange(start, end); foreach (IntercityCallModel item in Ranged) { IntercitySelection selItem = new IntercitySelection( item.Duration * item.Price, item.DateOfCall, item.Surname); Add(selItem); } return(Get()); }
public void Update(IDataModel model) { IntercitySelection SelModel = (IntercitySelection)model; string cost = SelModel.callPrice.ToString().Replace(".", ","); string updQue = $"UPDATE {tableName} SET Cost = @price" + $" WHERE SURNAME LIKE '{SelModel.surname}'"; OleDbCommand updCommand = new OleDbCommand(updQue, connection); updCommand.Parameters.Add(new OleDbParameter("@price", OleDbType.Double)); updCommand.Parameters["@price"].Value = cost; connection.Open(); updCommand.ExecuteNonQuery(); connection.Close(); }
public void Add(IDataModel model) { IntercitySelection call = (IntercitySelection)model; string price = call.callPrice.ToString().Replace(",", "."); string AppendQuery = $"INSERT INTO {tableName}(Cost, DateOfCall,SURNAME) " + $"VALUES({price}" + $",'{call.Date}'" + $",'{call.surname}')"; connection.Open(); OleDbCommand query = new OleDbCommand(AppendQuery, connection); query.ExecuteNonQuery(); connection.Close(); }
private List <IDataModel> Get() { List <IDataModel> selections = new List <IDataModel>(); connection.Open(); string ReqText = $"SELECT * FROM {tableName}"; OleDbCommand getReq = new OleDbCommand(ReqText, connection); OleDbDataReader reader = getReq.ExecuteReader(); while (reader.Read()) { IntercitySelection model = new IntercitySelection((double)(reader[1]), (DateTime)reader[2], (string)reader[3]); selections.Add(model); } connection.Close(); return(selections); }
private void AddPercentsButton_Click(object sender, EventArgs e) { var All = selectionReqs.GroupBy(GroupRows.Cost); SelectionDataView.Rows.Clear(); List <IDataModel> updatedList = new List <IDataModel>(); switch (PercentsEn.SelectedIndex) { case 0: foreach (IntercitySelection item in All) { IntercitySelection model = new IntercitySelection( item.callPrice + (item.callPrice / 100) * 5, item.Date, item.surname); updatedList.Add(model); } break; case 1: foreach (IntercitySelection item in All) { IntercitySelection model = new IntercitySelection( item.callPrice + (item.callPrice / 100) * 10, item.Date, item.surname); updatedList.Add(model); } break; case 2: foreach (IntercitySelection item in All) { IntercitySelection model = new IntercitySelection( item.callPrice + (item.callPrice / 100) * 15, item.Date, item.surname); updatedList.Add(model); } break; case 3: foreach (IntercitySelection item in All) { IntercitySelection model = new IntercitySelection( item.callPrice + (item.callPrice / 100) * 20, item.Date, item.surname); updatedList.Add(model); } break; default: foreach (IntercitySelection item in All) { IntercitySelection model = new IntercitySelection( item.callPrice + (item.callPrice / 100) * 5, item.Date, item.surname); updatedList.Add(model); } break; } foreach (IntercitySelection item in updatedList) { selectionReqs.Update(item); } updatedList = selectionReqs.GroupBy(GroupRows.Cost); foreach (IntercitySelection item in updatedList) { SelectionDataView.Rows.Add(item.callPrice, item.Date, item.surname); } }