public async Task PersistInfo() { if (!Validate()) throw new Exception("Client details not valid"); string sqlCmdString = "Insert Into dbo.clients (client_code, client_name, tin_no, main_address, primary_contact_name, primary_contact, primary_email) " + "Values (@client_code, @client_name, @tin_no, @main_address, @primary_contact_name, @primary_contact, @primary_email)"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); if (ClientCode == null) await AssignClientCode(); await Task.Run(() => { try { sqlCmd.Parameters.Add(new SqlParameter("@client_code", ClientCode)); sqlCmd.Parameters.Add(new SqlParameter("@client_name", ClientName)); sqlCmd.Parameters.Add(new SqlParameter("@tin_no", TinNo)); sqlCmd.Parameters.Add(new SqlParameter("@main_address", MainAddress)); sqlCmd.Parameters.Add(new SqlParameter("@primary_contact", PrimaryContact)); sqlCmd.Parameters.Add(new SqlParameter("@primary_contact_name", PrimaryContactName)); sqlCmd.Parameters.Add(new SqlParameter("@primary_email", PrimaryEmail)); sqlCmd.Transaction = myDb.InitiateTransaction(); sqlCmd.ExecuteNonQuery(); IsPersist = true; } catch (IOException ex) { GlobalAppStatus.AppStatus.StatusMessage(ex.Message, GlobalAppStatus.MessageType.ERROR); myDb.EndTransaction(true); } catch (SqlException ex) { GlobalAppStatus.AppStatus.StatusMessage(ex.Message, GlobalAppStatus.MessageType.ERROR); myDb.EndTransaction(true); } finally { myDb.EndTransaction(); } }); }
public async Task UpdateInfo() { string sqlCmdString = "Update dbo.order_forms " + "Set order_approved = @order_approved, order_poc_no = @order_poc_no, order_hardcopy_url = @order_hardcopy_url " + "Where order_id = @order_id"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); if (OrderId == null) await AssignOrderId(); await Task.Run(() => { try { sqlCmd.Parameters.Add(new SqlParameter("@order_id", OrderId)); sqlCmd.Parameters.Add(new SqlParameter("@order_approved", IsApproved)); sqlCmd.Parameters.Add(new SqlParameter("@order_poc_no", (PocNo == null) ? "" : PocNo)); sqlCmd.Parameters.Add(new SqlParameter("@order_hardcopy_url", (OrderHardcopyUrl == null) ? "" : OrderHardcopyUrl)); sqlCmd.Transaction = myDb.InitiateTransaction(); sqlCmd.ExecuteNonQuery(); IsPersist = true; } catch (Exception ex) { myDb.EndTransaction(true); throw ex; } finally { myDb.EndTransaction(); } }); }
public async Task PersistInfo() { if (!Validate()) throw new Exception("Client details not valid"); string sqlCmdString = "Insert Into dbo.challans (book_no, sl_no, challan_date, challan_type, order_id, freight_charge, vehicle_no, driver_mobile, consignment_note_no, transporter_name, vat, cst, special_note, received_amount) " + "Values (@book_no, @sl_no, @challan_date, @challan_type, @order_id, @freight_charge, @vehicle_no, @driver_mobile, @consignment_note_no, @transporter_name, @vat, @cst, @special_note, @received_amount)"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); await Task.Run(() => { try { sqlCmd.Parameters.Add(new SqlParameter("@book_no", BookNo)); sqlCmd.Parameters.Add(new SqlParameter("@sl_no", ChallanNo)); sqlCmd.Parameters.Add(new SqlParameter("@challan_date", ChallanDate)); sqlCmd.Parameters.Add(new SqlParameter("@challan_type", ChallanType.TypeName)); sqlCmd.Parameters.Add(new SqlParameter("@order_id", OrderForm.OrderId)); sqlCmd.Parameters.Add(new SqlParameter("@freight_charge", FreightCharge)); sqlCmd.Parameters.Add(new SqlParameter("@vehicle_no", VehicleNo)); sqlCmd.Parameters.Add(new SqlParameter("@driver_mobile", DriverMobile)); sqlCmd.Parameters.Add(new SqlParameter("@consignment_note_no", ConsignmentNoteNo)); sqlCmd.Parameters.Add(new SqlParameter("@transporter_name", TransporterName)); sqlCmd.Parameters.Add(new SqlParameter("@vat", Vat)); sqlCmd.Parameters.Add(new SqlParameter("@cst", Cst)); sqlCmd.Parameters.Add(new SqlParameter("@special_note", SpecialNote)); sqlCmd.Parameters.Add(new SqlParameter("@received_amount", ReceivedAmount)); sqlCmd.Transaction = myDb.InitiateTransaction(); sqlCmd.ExecuteNonQuery(); IsPersist = true; } catch (IOException ex) { GlobalAppStatus.AppStatus.StatusMessage(ex.Message, GlobalAppStatus.MessageType.ERROR); myDb.EndTransaction(true); } catch (SqlException ex) { GlobalAppStatus.AppStatus.StatusMessage(ex.Message, GlobalAppStatus.MessageType.ERROR); myDb.EndTransaction(true); } finally { myDb.EndTransaction(); } }); }
async Task UpdateInfo() { if (!IsPersist || !IsUpdated) return; string sqlCmdString = "Update dbo.stock_items " + "Set item_rate = @item_rate, stock_qty = @stock_qty, item_name = @item_name, item_description = @item_description " + "Where item_sku_code = @item_sku_code"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); await Task.Run(() => { try { sqlCmd.Parameters.Add(new SqlParameter("@item_rate", ItemRate)); sqlCmd.Parameters.Add(new SqlParameter("@stock_qty", StockQty)); sqlCmd.Parameters.Add(new SqlParameter("@item_name", ItemName)); sqlCmd.Parameters.Add(new SqlParameter("@item_description", (ItemDescription == null) ? "" : ItemDescription)); sqlCmd.Parameters.Add(new SqlParameter("@item_sku_code", ItemSkuCode)); sqlCmd.Transaction = myDb.InitiateTransaction(); sqlCmd.ExecuteNonQuery(); IsUpdated = false; } catch(Exception ex) { myDb.EndTransaction(true); throw ex; } finally { myDb.EndTransaction(); } }); }
public async void PersistInfo() { if (!Validate()) throw new Exception("Stock Item details not valid"); if (IsPersist && IsUpdated) { await UpdateInfo(); return; } else if (IsPersist && !IsUpdated) return; string sqlCmdString = "Insert Into dbo.stock_items (item_sku_code, item_rate, stock_qty, item_name, item_description) " + "Values (@item_sku_code, @item_rate, @stock_qty, @item_name, @item_description)"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); await Task.Run(() => { try { sqlCmd.Parameters.Add(new SqlParameter("@item_sku_code", ItemSkuCode)); sqlCmd.Parameters.Add(new SqlParameter("@item_rate", ItemRate)); sqlCmd.Parameters.Add(new SqlParameter("@stock_qty", StockQty)); sqlCmd.Parameters.Add(new SqlParameter("@item_name", ItemName)); sqlCmd.Parameters.Add(new SqlParameter("@item_description", (ItemDescription == null) ? "" : ItemDescription)); sqlCmd.Transaction = myDb.InitiateTransaction(); sqlCmd.ExecuteNonQuery(); IsPersist = true; } catch(Exception ex) { myDb.EndTransaction(true); throw ex; } finally { myDb.EndTransaction(); } }); }
public async void UpdateStockQty() { string sqlCmdString = "Update dbo.stock_items Set stock_qty = @stock_qty Where item_sku_code = @item_sku_code"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); await Task.Run(() => { try { sqlCmd.Parameters.Add(new SqlParameter("@item_sku_code", ItemSkuCode)); sqlCmd.Parameters.Add(new SqlParameter("@stock_qty", StockQty)); sqlCmd.Transaction = myDb.InitiateTransaction(); sqlCmd.ExecuteNonQuery(); IsPersist = true; } catch(Exception ex) { myDb.EndTransaction(true); throw ex; } finally { myDb.EndTransaction(); } }); }