//functie pentru stergere sofer din baza de date protected async System.Threading.Tasks.Task GridDeleteButtonClick(MouseEventArgs args, object data) { List <Models.FirmaCurierat.Soferi> drivers2 = new List <Models.FirmaCurierat.Soferi>(); FirmaCurierat.Models.FirmaCurierat.Soferi data2 = new Models.FirmaCurierat.Soferi(); data2 = (Models.FirmaCurierat.Soferi)data; drivers2 = drivers; try { if (await DialogService.Confirm("Do you want to delete this record?") == true) { drivers = new List <Models.FirmaCurierat.Soferi>(); SqlConnection scn = new SqlConnection(); string ServerName = Environment.MachineName; string database = "CurieratVladProiect"; string ConnectionString = String.Format(@"Server={0}\SQLEXPRESS;Initial Catalog={1}; Integrated Security = SSPI", ServerName, database); scn.ConnectionString = ConnectionString; SqlCommand scmd = new SqlCommand("delete from soferi where id_sofer = @id", scn); scmd.Parameters.Clear(); scmd.Parameters.AddWithValue("@id", data2.id_sofer); scn.Open(); scmd.ExecuteNonQuery(); } } catch (System.Exception rlvMailerDeleteMailException) { NotificationService.Notify(NotificationSeverity.Error, $"Error", $"Driver has orders in delivery!"); return; } drivers2.RemoveAll(d => d.id_sofer == data2.id_sofer); drivers = drivers2; grid0.Refresh(); this.StateHasChanged(); }
protected override async System.Threading.Tasks.Task OnInitializedAsync() { //initializare liste driver = new Models.FirmaCurierat.Soferi(); cars = new Models.FirmaCurierat.Masini(); carsList = new List <Models.FirmaCurierat.Masini>(); coordsList = new List <Models.FirmaCurierat.Dispeceri>(); // SqlConnection scn = new SqlConnection(); string ServerName = Environment.MachineName; //connection string general string database = "CurieratVladProiect"; string ConnectionString = String.Format(@"Server={0}\SQLEXPRESS;Initial Catalog={1}; Integrated Security = SSPI", ServerName, database); //initializare liste coordsList = new List <Models.FirmaCurierat.Dispeceri>(); carsList = new List <Models.FirmaCurierat.Masini>(); //comanda string sqlCommand = "select * from dispeceri"; dataHelper = new DataBaseManagement.DataManagement(); // scn.Open(); List <Models.FirmaCurierat.Masini> tempList = new List <Models.FirmaCurierat.Masini>(); //apelare functie generala pentru obtinerea unei liste de elemente din baza de date coordsList = await dataHelper.LoadData <Models.FirmaCurierat.Dispeceri, dynamic>(sqlCommand, new { }, ConnectionString); sqlCommand = "select * from masini"; //tot apelare functie generala tempList = await dataHelper.LoadData <Models.FirmaCurierat.Masini, dynamic>(sqlCommand, new { }, ConnectionString); sqlCommand = "select id_masina from soferi"; List <int> forSorting = new List <int>(); forSorting = await dataHelper.LoadData <int, dynamic>(sqlCommand, new { }, ConnectionString); //aleg doar masinile care nu au asociate un sofer, relatia fiind de 1->1 carsList = tempList.Where(i => forSorting.Contains(i.id_masina) == false).ToList(); }