private void simpleButtonAddUpdate_Click(object sender, EventArgs e) { using (var db = new PUEntitiesOne()) { if (textEditFaculty.Text == null || textEditFaculty.Text == "") { MessageBox.Show("Полето трябва да е запълнено"); return; } if (isUpdate) { var row = db.Faculties.FirstOrDefault(x => x.id == data.id); row.facultyName = textEditFaculty.Text; } else { Faculty f = new Faculty(); f.facultyName = textEditFaculty.Text; db.Faculties.Add(f); } try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Hide(); } }
private void DeleteOperation() { var cour = gridView.GetFocusedRow() as Cours; DialogResult dialogResult = MessageBox.Show("Желаете ли да изтриете този запис", "Подтвърдете", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { using (var db = new PUEntitiesOne()) { db.Courses.Attach(cour); db.Courses.Remove(cour); try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Имате съществуващ запис в друга таблица с тези данни"); return; } } } }
private void DeleteOperation() { var con = gridView.GetFocusedRow() as Contraget; DataCheck(con); DialogResult dialogResult = MessageBox.Show("Желаете ли да изтриете този запис", "Подтвърдете", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { using (var db = new PUEntitiesOne()) { db.Entry(con).State = System.Data.Entity.EntityState.Deleted; db.Contragets.Remove(con); try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Имате съществуващ запис в друга таблица с тези данни"); return; } } } LoadData(); }
private void DeleteOperation() { var edu = gridView.GetFocusedRow() as Educator; DataCheck(edu); DialogResult dialogResult = MessageBox.Show("Желаете ли да изтриете този запис", "Подтвърдете", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { using (var db = new PUEntitiesOne()) { //db.Entry(edu).State = EntityState.Deleted; db.Educators.Attach(edu); db.Educators.Remove(edu); try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Имате съществуващ запис в друга таблица с тези данни"); return; } } } }
private void simpleButton1_Click(object sender, EventArgs e) { if (DataCheck()) { return; } using (var db = new PUEntitiesOne()) { if (isUpdate) { var course = db.Courses.FirstOrDefault(x => x.id == cours.id); course.protocol = textEditProtocol.Text; course.courseDate = dateEdit1.DateTime; course.theme = textEditTheme.Text; course.anotation = textEditAnotation.Text; course.totalHour = int.Parse(textEditTotalHour.Text); course.totalCredit = int.Parse(textEditTotalCredit.Text); course.areaId = int.Parse(treeListLookUpEdit1.EditValue.ToString()); course.educatorId = int.Parse(treeListLookUpEdit2.EditValue.ToString()); } else { Cours course = new Cours(); course.protocol = textEditProtocol.Text; course.courseDate = dateEdit1.DateTime; course.theme = textEditTheme.Text; course.anotation = textEditAnotation.Text; course.totalHour = int.Parse(textEditTotalHour.Text); course.totalCredit = int.Parse(textEditTotalCredit.Text); course.areaId = int.Parse(treeListLookUpEdit1.EditValue.ToString()); course.educatorId = int.Parse(treeListLookUpEdit2.EditValue.ToString()); db.Courses.Add(course); } try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Hide(); } }
private void DeleteOperation() { var area = gridView1.GetFocusedRow() as Area; //id = int.Parse(gridView1.GetFocusedRowCellValue("id").ToString()); //int idArea = int.Parse(area.id.ToString()); DataCheck(area); DialogResult dialogresult = MessageBox.Show("Желаете ли да изтриете този запис", "Подтвърдете", MessageBoxButtons.YesNo); if (dialogresult == DialogResult.Yes) { using (var db = new PUEntitiesOne()) { //bool educator = db.Educators.Any(x => x.areaId == area.id); //bool courses = db.Courses.Any(x => x.areaId == area.id); //if (educator || courses) //{ // MessageBox.Show("Имате съществуващ запис в друга таблица с тези данни"); // return; //} //db.DeleteArea(id); db.Entry(area).State = System.Data.Entity.EntityState.Deleted; db.Areas.Remove(area); try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Имате съществуващ запис в друга таблица с тези данни"); return; //MessageBox.Show(ex.ToString()); } LoadData(); } } }
private void simpleButtonContragent_Click(object sender, EventArgs e) { using (var db = new PUEntitiesOne()) { if (textEditName.Text == null || textEditName.Text == "" || textEditEIK.Text == "" || textEditMOL.Text == "") { MessageBox.Show("Полето трябва да е запълнено"); return; } if (isUpdate) { var con = db.Contragets.FirstOrDefault(x => x.id == data.id); con.name = textEditName.Text; con.address = textEditAddress.Text; con.EIK = textEditEIK.Text; con.MOL = textEditMOL.Text; } else { Contraget con = new Contraget(); con.name = textEditName.Text; con.address = textEditAddress.Text; con.EIK = textEditEIK.Text; con.MOL = textEditMOL.Text; db.Contragets.Add(con); } try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Hide(); } }
private void simpleButtonAddUpdate_Click(object sender, EventArgs e) { if (textEditEducatorName.Text == null || textEditEducatorName.Text == "" || treeListLookUpEdit1.EditValue == null || treeListLookUpEditArea.EditValue == null) { MessageBox.Show("Въведете валидни данни"); return; } using (var db = new PUEntitiesOne()) { if (isUpdate) { var edu = db.Educators.FirstOrDefault(x => x.id == data.id); edu.educatorName = textEditEducatorName.Text; edu.areaId = int.Parse(treeListLookUpEditArea.EditValue.ToString()); edu.faculcyId = int.Parse(treeListLookUpEdit1.EditValue.ToString()); } else { Educator edu = new Educator(); edu.educatorName = textEditEducatorName.Text; edu.areaId = int.Parse(treeListLookUpEditArea.EditValue.ToString()); edu.faculcyId = int.Parse(treeListLookUpEdit1.EditValue.ToString()); db.Educators.Add(edu); } try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Hide(); } }
//public bool IsNumber(object value) //{ // return value is double // || value is decimal; //} //public List<Data> Fill() //{ // //db.SaveChanges е закоментирано !!!!!!!! // var listData = new List<Data>(); // foreach (var item in ) // { // if (IsNumber(item)) // { // //listData.Add(int.Parse(item.ToString())); // } // } // return listData; //} private void simpleButtonAddUpdate_Click(object sender, EventArgs e) { //Трябва да се разкоментира и да се направи условие int contractNum = int.Parse(textEditContractNum.Text); DateTime contractDate = textEditContractDate.DateTime; DateTime startDate = dateEditStart.DateTime; DateTime endDate = dateEditEnd.DateTime; decimal priceWithCredit = decimal.Parse(textEditWithCredit.EditValue.ToString()); double totalWihtCredit = double.Parse(textEditTotalCredit.Text); double priceWithoutCredit = double.Parse(textEditWithCredit.EditValue.ToString()); double totalWihtoutCredit = double.Parse(textEditTotalWithoutCredit.EditValue.ToString()); double totalSum = double.Parse(textEditTotalOfContracts.EditValue.ToString()); double DDS = double.Parse(textEditDDS.EditValue.ToString()); double DKPRPS = double.Parse(textEditDKPRPS.EditValue.ToString()); double honorar = double.Parse(textEditHonorar.EditValue.ToString()); double materialExprenses = double.Parse(textEditMaterialExpense.EditValue.ToString()); if (contractNum == 0 || contractDate == DateTime.MinValue || treeListLookUpEditContragent.EditValue != "" || treeListLookUpEditCourse.EditValue != "" || treeListLookUpEditEducator.EditValue != "" || startDate == DateTime.MinValue || endDate == DateTime.MinValue) { MessageBox.Show("Трябва да въведете валидни данни"); return; } using (var db = new PUEntitiesOne()) { if (isUpdate) { var row = db.Contracts.FirstOrDefault(x => x.id == contract.id); row.contractNumber = int.Parse(textEditContractNum.EditValue.ToString()); row.contractDate = textEditContractDate.DateTime; row.contragentId = int.Parse(treeListLookUpEditContragent.EditValue.ToString()); row.courseId = int.Parse(treeListLookUpEditCourse.EditValue.ToString()); row.educatorId = int.Parse(treeListLookUpEditEducator.EditValue.ToString()); row.startDate = dateEditStart.DateTime; row.endDate = dateEditEnd.DateTime; row.priceWithCredit = decimal.Parse(textEditWithCredit.EditValue.ToString()); row.totalWithCredit = int.Parse(textEditTotalCredit.EditValue.ToString()); row.priceWithoutCredit = decimal.Parse(textEditWithoutCredit.EditValue.ToString()); row.totalWithoutCredit = int.Parse(textEditTotalWithoutCredit.EditValue.ToString()); row.sumOfContract = int.Parse(textEditTotalOfContracts.EditValue.ToString()); row.DDS = int.Parse(textEditDDS.EditValue.ToString()); row.deductionsForPU = int.Parse(textEditPU.EditValue.ToString()); row.deductionsForDKPRPS = int.Parse(textEditDKPRPS.EditValue.ToString()); row.remunerationFee = int.Parse(textEditHonorar.EditValue.ToString()); row.materialCost = int.Parse(textEditMaterialExpense.EditValue.ToString()); } else { Contract con = new Contract(); con.contractNumber = int.Parse(textEditContractNum.EditValue.ToString()); con.contractDate = textEditContractDate.DateTime; con.contragentId = int.Parse(treeListLookUpEditContragent.EditValue.ToString()); con.courseId = int.Parse(treeListLookUpEditCourse.EditValue.ToString()); con.educatorId = int.Parse(treeListLookUpEditEducator.EditValue.ToString()); con.startDate = dateEditStart.DateTime; con.endDate = dateEditEnd.DateTime; con.priceWithCredit = decimal.Parse(textEditWithCredit.EditValue.ToString()); con.totalWithCredit = int.Parse(textEditTotalCredit.EditValue.ToString()); con.priceWithoutCredit = decimal.Parse(textEditWithoutCredit.EditValue.ToString()); con.totalWithoutCredit = int.Parse(textEditTotalWithoutCredit.EditValue.ToString()); con.sumOfContract = int.Parse(textEditTotalOfContracts.EditValue.ToString()); con.DDS = int.Parse(textEditDDS.EditValue.ToString()); con.deductionsForPU = int.Parse(textEditPU.EditValue.ToString()); con.deductionsForDKPRPS = int.Parse(textEditDKPRPS.EditValue.ToString()); con.remunerationFee = int.Parse(textEditHonorar.EditValue.ToString()); con.materialCost = int.Parse(textEditMaterialExpense.EditValue.ToString()); db.Contracts.Add(con); } try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Hide(); } }