//action 'Delete' exist object from grid private void btnDeleteComplex_Click(object sender, EventArgs e) { //return if element by index is not exist if (!(TypePlaceList.Count > indexSelectedElem)) { return; } //delete selected item of grid by field 'Code' TypePlace item = TypePlaceList[indexSelectedElem]; bool result = CheckAfterDelete(item.CodeI); //update data for grid gridTypePlaceList.DataSource = HandleDataForGrid(urlDataGrid); //step up in grid position if (result) { --indexSelectedElem; } if (indexSelectedElem < 0) { indexSelectedElem = 0; } gridTypePlaceList.CurrentRow = gridTypePlaceList.Rows[indexSelectedElem]; //define new currentRow DataUpdateForBottomPanel( TypePlaceList[indexSelectedElem].CodeI ); }
//action 'Add' new object to grid private void btnAddComplex_Click(object sender, EventArgs e) { //change property 'Text' of the btnSave for 'Add' action btnSaveTypePlace.Text = "Додати"; //refresh data for field 'Code' typePlaceData = new TypePlace { ParamType = 1 }; bsTypePlace.DataSource = typePlaceData; //refresh data for field 'Uk' ukTypePlace = new TypePlaceTr { Lang = Langs[0] }; typePlaceData.TypePlaceTr.Add(ukTypePlace); bsUkLangTypePlace.DataSource = ukTypePlace; //refresh data for field 'Ru' ruTypePlace = new TypePlaceTr { Lang = Langs[1] }; typePlaceData.TypePlaceTr.Add(ruTypePlace); bsRuLangTypePlace.DataSource = ruTypePlace; //refresh data for field 'Ru' enTypePlace = new TypePlaceTr { Lang = Langs[2] }; typePlaceData.TypePlaceTr.Add(enTypePlace); bsEnLangTypePlace.DataSource = enTypePlace; //stop perform if elements have 'Enabled' -> false if (!ControlEnabledActiveElements) { return; } //change 'Enabled' state for elements ControlEnabledActiveElements = false; }
/// <summary> /// check result data after 'Update' /// </summary> /// <param name="updateItem"></param> /// <returns></returns> private TypePlace CheckAfterUpdate(TypePlace updateItem) { UpdateLayer dictDelegat = new UpdateLayer(_layer.Update); TypePlace result = dictDelegat(typePlaceData); if (result == null) { MessageShow.ShowError(UpdateMess); //select first element of grid by default result = TypePlaceList[0]; } return(result); }
/// <summary> /// check result data after 'Create' /// </summary> /// <param name="createItem"></param> /// <returns></returns> private TypePlace CheckAfterCreate(TypePlace createItem) { CreateLayer dictDelegat = new CreateLayer(_layer.Create); TypePlace result = dictDelegat(createItem); if (result == null) { MessageShow.ShowError(CreateMess); //select first element of grid by default result = TypePlaceList[0]; } return(result); }
private TypePlace CheckAfterGetQuery(int codeI) { GetDictionaryLayer dictDelegat = new GetDictionaryLayer(_layer.GetDictionary); TypePlace result = dictDelegat(codeI); if (result == null) { MessageShow.ShowError(GetMess); //set select first element of grid result = TypePlaceList[0]; } return(result); }
//action 'Save' object to grid private void btnSave_Click(object sender, EventArgs e) { //refresh bottom panel int codeIAfter = 0; if (btnSaveTypePlace.Text == "Додати") { //send created object TypePlace result = CheckAfterCreate(typePlaceData); codeIAfter = result.CodeI; //update data for grid gridTypePlaceList.DataSource = HandleDataForGrid(urlDataGrid); indexSelectedElem = _typePlaceList.FindIndex(el => el.CodeI == result.CodeI); //select certain item into grid gridTypePlaceList.CurrentRow = gridTypePlaceList.Rows[indexSelectedElem]; //set default state for 'Text' of the btnSave btnSaveTypePlace.Text = "Зберегти"; } else if (btnSaveTypePlace.Text == "Зберегти") { //save changes TypePlace result = CheckAfterUpdate(typePlaceData); codeIAfter = result.CodeI; //save last selected item indexSelectedElem = gridTypePlaceList.CurrentRow.Index; //update data for grid gridTypePlaceList.DataSource = HandleDataForGrid(urlDataGrid); //select certain item into grid gridTypePlaceList.CurrentRow = gridTypePlaceList.Rows[indexSelectedElem]; } DataUpdateForBottomPanel(codeIAfter); //stop perform if elements have 'Enabled' -> true if (ControlEnabledActiveElements) { return; } //change 'Enabled' state for elements ControlEnabledActiveElements = true; }
//refresh changed data for bottom panel private void DataUpdateForBottomPanel(int codeI) { //get object by parameter 'code' from service typePlaceData = CheckAfterGetQuery(codeI); //use data for binding source bsTypePlace.DataSource = typePlaceData; //define binding for source of the 'Uk' ukTypePlace = typePlaceData.TypePlaceTr.FirstOrDefault(rec => rec.Lang.TrimEnd() == Langs[0]); if (ukTypePlace == null) { ukTypePlace = new TypePlaceTr { Lang = Langs[0] }; typePlaceData.TypePlaceTr.Add(ukTypePlace); } bsUkLangTypePlace.DataSource = ukTypePlace; //defined binding for source of the 'Ru' ruTypePlace = typePlaceData.TypePlaceTr.FirstOrDefault(rec => rec.Lang.TrimEnd() == Langs[1]); if (ruTypePlace == null) { ruTypePlace = new TypePlaceTr { Lang = Langs[1] }; typePlaceData.TypePlaceTr.Add(ruTypePlace); } bsRuLangTypePlace.DataSource = ruTypePlace; //define binding for source of the 'En' enTypePlace = typePlaceData.TypePlaceTr.FirstOrDefault(rec => rec.Lang.TrimEnd() == Langs[2]); if (enTypePlace == null) { enTypePlace = new TypePlaceTr { Lang = Langs[2] }; typePlaceData.TypePlaceTr.Add(enTypePlace); } bsEnLangTypePlace.DataSource = enTypePlace; }