public void AddItemToRevision(string itemId, int newNumber) { var db = new dbDataContext(); lock (db) { var match = (from i in db.GetTable<items_table>() where i.item_id == itemId select i).SingleOrDefault(); if (match != null) { match.number_left += newNumber; db.SubmitChanges(); } else { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(42)); } } }
public void SellItem(string itemId, int number, DateTime timeOfSelling, double sum) { var db = new dbDataContext(); lock (db) { int dailyId = GetLastOpenedGlobalSessionDailyId(); Table<sold_bar_history_table> soldBarTable = db.GetTable<sold_bar_history_table>(); var soldItem = new sold_bar_history_table { daily_id = dailyId, amount_sold = number, item_id = itemId, sale_time = timeOfSelling, comments = " " }; soldBarTable.InsertOnSubmit(soldItem); db.SubmitChanges(); AddMoneyToCash(sum, dailyId); AddItemToRevision(itemId, number*(-1)); } }
public void DeleteExpense(int expensesId) { var db = new dbDataContext(); lock (db) { var item = (from i in db.GetTable<expenses_t>() where i.expense_id == expensesId select i).SingleOrDefault(); if (item != null) { Table<expenses_t> expensesTable = db.GetTable<expenses_t>(); expensesTable.DeleteOnSubmit(item); db.SubmitChanges(); } } }
public void DeleteDevice(int deviceId) { var db = new dbDataContext(); lock (db) { var matchedResult = (from d in db.GetTable<devices_t>() where d.device_id == deviceId select d).SingleOrDefault(); if (matchedResult != null) { Table<devices_t> devicesTable = db.GetTable<devices_t>(); devicesTable.DeleteOnSubmit(matchedResult); DeleteAllEndPointsOfDevice(deviceId); db.SubmitChanges(); } } }
public void DeleteConsole(string consoleId) { var db = new dbDataContext(); lock (db) { // string selectedTable = (string)dataGridViewConsolesList.CurrentRow.Cells[0].Value; var consoleToDelete = (from t in db.GetTable<tables_t>() where t.playstation_id.Equals(consoleId) select t).SingleOrDefault(); var deleteTimezonePrices = (from tp in db.GetTable<playstation_timezone>() where tp.playstation_id.Equals(consoleId) select tp); var deleteEndPoints = (from ep in db.GetTable<device_endpoints_t>() where ep.playstation_id == consoleId select ep); var sessionsToDelete = (from s in db.GetTable<days_sessions_t>() where s.playstation_id == consoleId select s); Table<clients_per_session_t> cps = db.GetTable<clients_per_session_t>(); foreach (var daysSessionsT in sessionsToDelete) { days_sessions_t t = daysSessionsT; var clientsPerSessionToDelete = (from cp in db.GetTable<clients_per_session_t>() where cp.session_id == t.session_id select cp).SingleOrDefault(); if (clientsPerSessionToDelete != null) cps.DeleteOnSubmit(clientsPerSessionToDelete); db.SubmitChanges(); } if (consoleToDelete != null) { Table<days_sessions_t> daysSessionsTs = db.GetTable<days_sessions_t>(); Table<device_endpoints_t> deviceEndpointsTs = db.GetTable<device_endpoints_t>(); Table<tables_t> tablesTs = db.GetTable<tables_t>(); foreach (var deleteTimezonePrice in deleteTimezonePrices) { db.playstation_timezones.DeleteOnSubmit(deleteTimezonePrice); } daysSessionsTs.DeleteAllOnSubmit(sessionsToDelete); db.SubmitChanges(); deviceEndpointsTs.DeleteAllOnSubmit(deleteEndPoints); db.SubmitChanges(); tablesTs.DeleteOnSubmit(consoleToDelete); db.SubmitChanges(); } } }
public void AddMoneyToCash(double cash, int dailyId) { var db = new dbDataContext(); lock (db) { // int dId = GetOpenedGlobalSession().daily_id; var getCashFromCurrentSession = (from c in db.GetTable<cash_t>() where c.daily_id == dailyId select c).SingleOrDefault(); if (getCashFromCurrentSession != null) { getCashFromCurrentSession.cash_amount = getCashFromCurrentSession.cash_amount + cash; db.SubmitChanges(); } else { var cashTable = db.GetTable<cash_t>(); var cashT = new cash_t {cash_amount = cash, daily_id = dailyId}; cashTable.InsertOnSubmit(cashT); db.SubmitChanges(); } } }
public void CloseSessionWithUsualClient(DaySessionClass dsc, string comments, DateTime endTime) { var db = new dbDataContext(); lock (db) { int dayId = GetOpenedGlobalSession().daily_id; var sessionIdtoDelete = (from s in db.GetTable<days_sessions_t>() where s.daily_id == dayId where s.session_id == dsc.Сессия select s).SingleOrDefault(); if (sessionIdtoDelete == null) return; sessionIdtoDelete.end_game = endTime; sessionIdtoDelete.session_state = "closed"; // if (endTime - dsc.Начало < TimeSpan.FromHours(1)) // { // dsc.Счетчик = dsc.Оплачено - dsc.Счетчик; // } sessionIdtoDelete.payed_sum = dsc.Оплачено; sessionIdtoDelete.played_money = dsc.Счетчик; if (String.IsNullOrWhiteSpace(sessionIdtoDelete.comments)) { sessionIdtoDelete.comments = comments; } else { sessionIdtoDelete.comments += "\n" + comments; } UpdatePlaystationState(dsc.Приставка, "free"); while (true) { try { db.SubmitChanges(); break; } catch { MessageBox.Show( ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(3)); } } } }
//----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------When client will be able to store money on the card------------------------------------------------------ //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------This algorithm help to acount how much money should be paid by each client(if more than 1)-------------- //---------------------------------------Account that each player will pay equal sum of money, but if one of the cards do not have enough money-- //----------------------------------------another will pay for him!------------------------------------------------------------------------------ //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- // public void CloseSessionWithCard(DaySessionClass dsc, string comments, DateTime endTime) // { // var db = new dbDataContext(); // lock (db) // { // int dayId = GetOpenedGlobalSession().daily_id; // var sessionIdtoDelete = (from s in db.GetTable<days_sessions_t>() // where s.daily_id == dayId // where s.session_id == dsc.Сессия // select s).SingleOrDefault(); // if (sessionIdtoDelete == null) return; // sessionIdtoDelete.end_game = endTime; // sessionIdtoDelete.session_state = "closed"; // sessionIdtoDelete.money_left = dsc.Счетчик; // List<clients_per_session_t> clientsOnSession = GetListOfClientsPerExactSession(dsc.Сессия); // double playedMoney = dsc.Оплачено - dsc.Счетчик;//sessionIdtoDelete.payed_sum - sessionIdtoDelete.money_left; // double eachPlayerShouldPay = playedMoney/clientsOnSession.Count; // double nextShouldpayAdditional = 0; // do // { // foreach (var client in clientsOnSession) // { // var moneyOnClientCard = GetClientSavingsById(client.client_id); // if (moneyOnClientCard != null) // { // if (moneyOnClientCard.savings >= (eachPlayerShouldPay + nextShouldpayAdditional)) // { // playedMoney = playedMoney - (eachPlayerShouldPay + nextShouldpayAdditional); //// moneyOnClientCard.savings = moneyOnClientCard.savings - (eachPlayerShouldPay + nextShouldpayAdditional); // ChangeSavingsValueOfClient(moneyOnClientCard.client_id, // (moneyOnClientCard.savings - (eachPlayerShouldPay + nextShouldpayAdditional))*-1); // nextShouldpayAdditional = 0; // } // else // { // nextShouldpayAdditional = eachPlayerShouldPay - moneyOnClientCard.savings; // playedMoney = playedMoney - moneyOnClientCard.savings; //// moneyOnClientCard.savings = 0; // ChangeSavingsValueOfClient(moneyOnClientCard.client_id, 0); // } // } //// try //// { //// db.SubmitChanges(); //// } //// catch (Exception) //// { //// MessageBox.Show("Error during closing clients occured!"); //// } // } // } while (nextShouldpayAdditional > 0 && playedMoney > 0); // // // if (String.IsNullOrWhiteSpace(sessionIdtoDelete.comments)) // { // sessionIdtoDelete.comments = comments; // } // else // { // sessionIdtoDelete.comments += "\n" + comments; // } // UpdatePlaystationState(dsc.Приставка, "free"); // while (true) // { // try // { // db.SubmitChanges(); // break; // } // catch // { // MessageBox.Show( // ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(3)); // } // } // } // } //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- public void ChangeSavingsValueOfClient(string clientId, double sumToAdd) { var db = new dbDataContext(); lock (db) { var clientIdToChangeSavings = (from c in db.GetTable<account_savings_t>() where c.client_id == clientId select c).SingleOrDefault(); // var paymentTable = (from p in db.GetTable<payments_t>() // where ) if (clientIdToChangeSavings != null) { clientIdToChangeSavings.savings += sumToAdd; try { db.SubmitChanges(); InsertNewPaymentToClientHistory(clientId, sumToAdd); } catch (Exception) { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(4) + clientIdToChangeSavings.client_id); } } } }
private void InsertNewPaymentToClientHistory(string clientId, double cash) { var db = new dbDataContext(); lock (db) { var paymentsTable = db.GetTable<payments_t>(); var payments = new payments_t { client_id = clientId, date_of_transaction = DateTime.Now, put_cash = cash }; paymentsTable.InsertOnSubmit(payments); db.SubmitChanges(); } }
private void AddNewSaVingsForClient(string clientId) { var db = new dbDataContext(); lock (db) { Table<account_savings_t> personalInfoTable = db.GetTable<account_savings_t>(); var savings = new account_savings_t { client_id = clientId, savings = 0 }; personalInfoTable.InsertOnSubmit(savings); db.SubmitChanges(); } }
public void AddNewItem(string itemId, string categoryName, double cost, string description) { var db = new dbDataContext(); lock (db) { var match = (from i in db.GetTable<items_table>() where i.item_id == itemId select i).SingleOrDefault(); if (match == null) { Table<items_table> itemsTable = db.GetTable<items_table>(); var item = new items_table { item_id = itemId, item_num = db.GetTable<items_table>().Count(), number_left = 300, category_name = categoryName, cost = cost, item_description = description }; itemsTable.InsertOnSubmit(item); db.SubmitChanges(); } else { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(42)); } } }
public void UpdatePricesForTimeZone(List<string> playstationsToChange, string timeZoneName, int newPrice) { var db = new dbDataContext(); lock (db) { // for (int i = 0; i < 5; i++) // { try { foreach (string t in playstationsToChange) { var matchedRecord = (from price in db.GetTable<playstation_timezone>() where price.playstation_id == t where price.timezone_name == timeZoneName select price).SingleOrDefault(); if (matchedRecord == null) continue; try { matchedRecord.timezone_cost_per_hour = newPrice; db.SubmitChanges(); // break; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } catch (Exception) { // if (i <= 0) // { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance() .GetErrorWithLine(1, 88)); // } } // } } }
public void UpdatePlaystationState(string playstationId, string state) { var db = new dbDataContext(); lock (db) { var table = (from t in db.GetTable<tables_t>() where t.playstation_id == playstationId select t).SingleOrDefault(); if (table != null && table.playstation_id != null) { table.playstation_state = state; db.SubmitChanges(); } } }
public void UpdateClientInfo(client_info_t cInfo) { var db = new dbDataContext(); lock (db) { for (int i = 0; i < 5; i++) { try { var matchedRecord = (from c in db.GetTable<client_info_t>() where c.client_id == cInfo.client_id select c).SingleOrDefault(); if (matchedRecord != null) { matchedRecord.name = cInfo.name; matchedRecord.birthday = cInfo.birthday; matchedRecord.email = cInfo.email; matchedRecord.phone = cInfo.phone; } db.SubmitChanges(); break; } catch (Exception) { if (i <= 0) { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance() .GetErrorWithLine(1, 88)); } } } } }
public void TransferOpenedSessionToNextGlobalSession(int sessionId) { var db = new dbDataContext(); lock (db) { for (int i = 0; i < 5; i++) { try { var sessionToTransfer = (from s in db.GetTable<days_sessions_t>() where s.session_id == sessionId select s).SingleOrDefault(); // sessionToTransfer.daily_id = sessionToTransfer.daily_id + 1; var lastOpenedGlobalSession = GetOpenedGlobalSession(); int dailyId = GetOpenedGlobalSession().daily_id; if (sessionToTransfer != null) { sessionToTransfer.daily_id = lastOpenedGlobalSession.daily_id; AddMoneyToCash(sessionToTransfer.payed_sum, dailyId); db.SubmitChanges(); break; } } catch (Exception) { if (i <= 0) { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance() .GetErrorWithLine(1, 88)); } } } } }
public void ChangePlaystation(DaySessionClass ds, string newPlaystation, string comments) { var db = new dbDataContext(); lock (db) { DateTime curTime = DateTime.Now; for (int i = 0; i < 5; i++) { try { var matchDs = (from os in db.GetTable<days_sessions_t>() where os.session_id == ds.Сессия select os).SingleOrDefault(); if (matchDs != null) { UpdatePlaystationState(matchDs.playstation_id, "free"); db.SubmitChanges(); matchDs.playstation_id = newPlaystation; decimal moneyLeftFromLastGame = (decimal) (matchDs.payed_sum - ds.Счетчик); TimeSpan paidTime = AddNewSessionController.AddNewSessionControllerInstance() .UpdateTimeLeft(moneyLeftFromLastGame, newPlaystation, 0, 18900, DateTime.Now); if (matchDs.start_game != null && matchDs.end_game != null) matchDs.end_game = curTime.Add(paidTime); if (String.IsNullOrWhiteSpace(matchDs.comments)) { matchDs.comments = "Пересел с " + ds.Приставка + " на " + newPlaystation + " " + comments; } else { matchDs.comments += "\n" + "Пересел с " + ds.Приставка + " на " + newPlaystation + " " + comments; } UpdatePlaystationState(newPlaystation, "busy"); // matchDs.session_discount += 5;// Discount because of replacing // matchDs.end_game db.SubmitChanges(); break; } MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(39)); } catch (Exception) { if (i <= 0) { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance() .GetErrorWithLine(1, 88)); } } } } }
// public void AddItemsToRevision(string itemId, int amountsold) // { // var db = new dbDataContext(); // lock (db) // { // // } // } public void AddNewOrUpdateBarRevisionRecord(int dailyId, string itemId, int amountSold, int amountBought, int left, int num) { var db = new dbDataContext(); lock (db) { var match = (from i in db.GetTable<bar_revision_t>() where i.item_id == itemId where i.daily_id == dailyId select i).SingleOrDefault(); if (match == null) { Table<bar_revision_t> soldBarTable = db.GetTable<bar_revision_t>(); var revisionItem = new bar_revision_t { bar_item_num = num, daily_id = dailyId, item_id = itemId, amount_sold = amountSold, amount_bought = amountBought, left_num = left }; soldBarTable.InsertOnSubmit(revisionItem); db.SubmitChanges(); } else { match.bar_item_num = num; match.amount_sold = amountSold; match.amount_bought = amountBought; match.left_num = left; db.SubmitChanges(); } } }
public void AddNewPromoUsage(int sessionid, string comment, double sum) { var db = new dbDataContext(); lock (db) { Table<promo_usage_history> usageHistoryTable = db.GetTable<promo_usage_history>(); var usageHistory = new promo_usage_history { daily_id = GetLastOpenedGlobalSessionDailyId(), promo_bonus_comment = comment, promo_discount_sum = sum, session_id = sessionid }; usageHistoryTable.InsertOnSubmit(usageHistory); db.SubmitChanges(); } }
public void CloseLastOpenedGlobalSession() { var db = new dbDataContext(); lock (db) { for (int i = 0; i < 5; i++) { try { var globalSession = (from gs in db.GetTable<global_session_t>() where gs.end_session == gs.start_session select gs).SingleOrDefault(); if (globalSession != null) { globalSession.end_session = DateTime.Now; db.SubmitChanges(); break; } } catch (Exception) { if (i <= 0) { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance() .GetErrorWithLine(1, 88)); } } } } }
public void AddNewStaffUser(personal_info_t userInfo) { var db = new dbDataContext(); lock (db) { Table<personal_info_t> personalInfoTable = db.GetTable<personal_info_t>(); personal_info_t user = userInfo; personalInfoTable.InsertOnSubmit(user); db.SubmitChanges(); } }
public void DeleteAllEndPointsOfDevice(int deviceId) { var db = new dbDataContext(); lock (db) { var matchedResult = (from d in db.GetTable<device_endpoints_t>() where d.device_id == deviceId select d); { Table<device_endpoints_t> devicesTable = db.GetTable<device_endpoints_t>(); devicesTable.DeleteAllOnSubmit(matchedResult); db.SubmitChanges(); } } }
public void AddPlayedMoneyToClientAndChangeHisDiscount(string clientId, double moneyToAdd) { if (moneyToAdd > 0) { var db = new dbDataContext(); lock (db) { var clientInfo = (from c in db.GetTable<client_info_t>() where c.client_id == clientId select c).SingleOrDefault(); if (clientInfo != null) { clientInfo.played_sum += moneyToAdd; var allDicountLevels = GetAllDiscountSteps(); var maxDiscount = allDicountLevels[0].discount; foreach (var step in allDicountLevels) { if (clientInfo.played_sum >= step.required_played_sum) { maxDiscount = step.discount; // clientInfo.pers_discount = step.discount; } } // if (maxDiscount > clientInfo.pers_discount) // { clientInfo.pers_discount = maxDiscount; db.SubmitChanges(); // } } } } }
public void DeleteClient(string clientId) { var db = new dbDataContext(); lock (db) { Table<client_info_t> personalInfoTable = db.GetTable<client_info_t>(); var client = (from c in db.GetTable<client_info_t>() where c.client_id == clientId select c).SingleOrDefault(); if (client != null) { personalInfoTable.DeleteOnSubmit(client); db.SubmitChanges(); } else { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(52)); } } }
public void AddToSessionDiscountSum(int sessionId, double discountToAdd) { var db = new dbDataContext(); lock (db) { for (int i = 0; i < 5; i++) { try { var matchedRecord = (from c in db.GetTable<days_sessions_t>() where c.session_id == sessionId select c).SingleOrDefault(); if (matchedRecord != null) { if (matchedRecord.session_discount == 0 || matchedRecord.session_discount == null) matchedRecord.session_discount = discountToAdd; else matchedRecord.session_discount += discountToAdd; } db.SubmitChanges(); break; } catch (Exception) { if (i <= 0) { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance() .GetErrorWithLine(1, 88)); } } } } }
public void DeleteDaySession() { var db = new dbDataContext(); lock (db) { var lastInsertedDaySession = (from ls in db.GetTable<days_sessions_t>() orderby ls.session_id descending select ls).FirstOrDefault(); var sessionToDelete = (from d in db.GetTable<days_sessions_t>() where d.session_id == lastInsertedDaySession.session_id select d).SingleOrDefault(); if (sessionToDelete == null) return; Table<days_sessions_t> deleteFromT = db.GetTable<days_sessions_t>(); deleteFromT.DeleteOnSubmit(sessionToDelete); db.SubmitChanges(); } }
public void ChangeBarItemPrice(string itemId, int newPrice) { var db = new dbDataContext(); lock (db) { var match = (from i in db.GetTable<items_table>() where i.item_id == itemId select i).SingleOrDefault(); if (match != null) { match.cost = newPrice; db.SubmitChanges(); } else { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(42)); } } }
public void DeleteDiscountStep(string name) { var db = new dbDataContext(); lock (db) { var match = (from m in db.GetTable<steps_of_discount_upgrading>() where m.name == name select m).SingleOrDefault(); if (match != null) { Table<steps_of_discount_upgrading> stepsOfDiscountUpgradingsTable = db.GetTable<steps_of_discount_upgrading>(); stepsOfDiscountUpgradingsTable.DeleteOnSubmit(match); db.SubmitChanges(); } else { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(28)); } } }
public void ChangeEndPointConsoleId(int endpointId, string changePlaystation, int deviceId) { var db = new dbDataContext(); lock (db) { var matched = (from ep in db.GetTable<device_endpoints_t>() where ep.endpoint_index == endpointId where ep.device_id == deviceId select ep).SingleOrDefault(); if (matched != null) { matched.playstation_id = changePlaystation; db.SubmitChanges(); } } }
public void DeleteSoldItem(int saleId) { var db = new dbDataContext(); lock (db) { int dailyId = GetLastOpenedGlobalSessionDailyId(); var item = (from i in db.GetTable<sold_bar_history_table>() where i.sale_id == saleId select i).SingleOrDefault(); if (item != null) { AddMoneyToCash((double) (GetItemDataById(item.item_id).Цена*item.amount_sold), dailyId); Table<sold_bar_history_table> soldItemsTable = db.GetTable<sold_bar_history_table>(); soldItemsTable.DeleteOnSubmit(item); db.SubmitChanges(); } } }
public void RemoveItem(string itemId) { var db = new dbDataContext(); lock (db) { var match = (from i in db.GetTable<items_table>() where i.item_id == itemId select i).SingleOrDefault(); if (match != null) { Table<items_table> itemsTable = db.GetTable<items_table>(); itemsTable.DeleteOnSubmit(match); db.SubmitChanges(); } else { MessageBox.Show(ErrorsAndWarningsMessages.ErrorsAndWarningsInstance().GetError(42)); } } }