private void SubmitForm() { var result = MsgBox.Show("Verificati daca datele sunt corecte si confirmati", "Confirmare", MessageBoxButton.OKCancel, MessageBoxImage.Information); if (result == MessageBoxResult.OK) { string sql = "BEGIN TRY BEGIN TRANSACTION INSERT INTO dbo.Invoice (Invoice, Supplier, DateIn, Subtotal, Tax, Total)" + $" VALUES ('{invoiceNumber}', '{supplier}', '{invoiceDate}', {subtotal}, {tax}, {total})"; foreach (var item in InvoiceDetailsCollection) { sql += " INSERT INTO dbo.InvoiceDetail (InvoiceId, ProductId, Quantity, PurchasePrice, Tax, TotalPrice)" + $" VALUES ((SELECT TOP 1 Id FROM dbo.Invoice WHERE Invoice='{invoiceNumber}' AND Supplier = '{supplier}' ORDER BY Id DESC ), (SELECT Id from dbo.Product WHERE Name='{item.ProductName}'), {item.Quantity}, {item.PurchasePrice}, {item.Tax}, {item.TotalPrice})"; sql += $" UPDATE dbo.Stock SET Quantity = Quantity + {item.Quantity} WHERE ProductId = (SELECT Id from dbo.Product WHERE Name='{item.ProductName}')"; } sql += "COMMIT END TRY BEGIN CATCH ROLLBACK END CATCH"; ServerResponseModel <InvoiceModel> response = invoiceData.AddInvoice(sql); if (response.Count > 0 || response.Error == null) { MsgBox.Show("Baza de date a fost acualizata cu succes!", " ", MessageBoxButton.OK, MessageBoxImage.Information); } else { MsgBox.Show("Cererea nu a fost procesata din cauza unei erori, iar produsul nu a fost adaugat", "Eroare de procesare", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public static ServerResponseModel sendUnityWebRequest(Dictionary <string, string> values, string url) { //adding user identification to all the requests to the server values.Add("userId", userIdentification); ServerResponseModel result = new ServerResponseModel(); WWWForm form = new WWWForm(); foreach (KeyValuePair <string, string> entry in values) { form.AddField(entry.Key, entry.Value); } UnityWebRequest uwr = UnityWebRequest.Post(url, form); uwr.SendWebRequest(); while (!uwr.isDone) { } if (uwr.isNetworkError) { Debug.Log("Error While Sending: " + uwr.error); } else { result = JsonUtility.FromJson <ServerResponseModel>(uwr.downloadHandler.text); } return(result); }
private async Task HandlerResponse <D>(D data, string errorText) { var responseModel = new ServerResponseModel <D> { ResponseData = data, Error = errorText }; await Response.WriteAsJsonAsync(responseModel); }
private void AddSale() { ShowProgressBar(); if (productCollection.Count > 0 && productCollection != null) { var payConfirmation = MsgBox.Show("Doriti sa incheiati tranzactia si sa platiti?", "Incheiere tranzactie", MessageBoxButton.YesNo, MessageBoxImage.Question); if (payConfirmation == MessageBoxResult.Yes) { var result = MsgBox.Show("Doriti sa imprimati bonul?", "Imprimare bon", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) { string sql = "BEGIN TRY" + " BEGIN TRANSACTION" + " INSERT INTO dbo.Sale (CashierId, Total)" + $" VALUES ((SELECT Id from [dbo].[User] WHERE IsActive=1), {amount})"; foreach (var item in ProductCollection) { sql += " INSERT INTO dbo.SaleDetail (SaleId, ProductId, Quantity, RetailPrice, Tax, Total)" + $" VALUES ((SELECT TOP 1 Id FROM dbo.Sale ORDER BY Id DESC ), (SELECT Id from dbo.Product WHERE Name='{item.ProductName}'), {quantity}, {item.Subtotal}, {item.Tax}, {item.SaleUnitValue})"; sql += $" UPDATE dbo.Stock SET Quantity = Quantity - {item.Quantity} WHERE ProductId = (SELECT Id from dbo.Product WHERE Name='{item.ProductName}')"; } sql += "COMMIT" + " END TRY" + " BEGIN CATCH" + " ROLLBACK " + " END CATCH"; ServerResponseModel <SalesModel> response = startupData.AddSale(sql); if (response.Error == null && response.Count > 0) { MsgBox.Show("Baza de date a fost acualizata cu succes!", " ", MessageBoxButton.OK, MessageBoxImage.Information); } else { MsgBox.Show("Cererea nu a fost procesata din cauza unei erori, iar produsul nu a fost adaugat", "Eroare de procesare", MessageBoxButton.OK, MessageBoxImage.Error); } ProductCollection = new ObservableCollection <SaleModelUI>(); Amount = 0; } else { ProductCollection = new ObservableCollection <SaleModelUI>(); Amount = 0; } } } else { MsgBox.Show("Cosul de cumparaturi este gol. Va rog sa scanati cel putin un produs!", "", MessageBoxButton.OK, MessageBoxImage.Exclamation); } HideProgressBar(); }
public static void CheckSubscriptionPriceChange() { var values = new Dictionary <string, string> { }; ServerResponseModel serverResponse = sendUnityWebRequest(values, CHECK_SUBSCRIPTION_PRICE_CHANGE); if (serverResponse.success) { PurchaseController.confirmSubscriptionPriceChange(serverResponse.result); } }
public static void verifyAndSaveUserPurchase(Product product) { var values = new Dictionary <string, string> { ["receipt"] = product.receipt }; ServerResponseModel serverResponse = sendUnityWebRequest(values, VERIFY_AND_SAVE_TOKEN_URL); PurchaseController.ConfirmPendingPurchase(product, serverResponse.success); }
public static void LoadGameOnline() { ServerResponseModel serverResponse = sendUnityWebRequest(new Dictionary <string, string>(), GET_GAME_DATA_URL); if (serverResponse.success) { GameDataController.SetGameData(JsonUtility.FromJson <GameData>(serverResponse.result)); } else { GameDataController.SetGameData(new GameData()); } }
public ServerResponseModel <InvoiceModel> GetAllInvoices() { ServerResponseModel <InvoiceModel> serverResponse = new ServerResponseModel <InvoiceModel>(); IEnumerable <InvoiceModel> invoiceModel; try { invoiceModel = sqlDataAccess.GetAllData <InvoiceModel>("dbo.spGetAllInvoices", "retailApp"); serverResponse.Data = invoiceModel; serverResponse.Count = invoiceModel.Count(); } catch (Exception ex) { serverResponse.Error = "Eroare la conexiunea cu baza de date " + ex.Message; } return(serverResponse); }
public ServerResponseModel <T> ExecuteRawSql <T>(string sql, string connectinStringName) { ServerResponseModel <T> response = new ServerResponseModel <T>(); string connectionString = GetConnectionString(connectinStringName); using (IDbConnection dbConnection = new SqlConnection(connectionString)) { dbConnection.Open(); try { response.Count = dbConnection.Execute(sql); } catch (Exception ex) { response.Error = ex.Message; } } return(response); }
public static IEnumerable <Item> Create(ServerResponseModel apiResponse) { return((from apiItem in apiResponse.Items let itemDefinition = MapItemDefinition(apiItem) select MapItem(itemDefinition, apiItem)).ToList()); }