private void gridViewVacations_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e) { if (e.OldValue != e.Value) { if (e.Row.Cells["colStartDate"].Value != null && e.Row.Cells["colEndDate"].Value != null) { bool ok = true; DateTime start = (DateTime)e.Row.Cells["colStartDate"].Value; DateTime end = (DateTime)e.Row.Cells["colEndDate"].Value; if (e.Column.Name == "colStartDate") { start = (DateTime)e.Value; ok = employee.ChangeStartDate(start, end); } if (e.Column.Name == "colEndDate") { end = (DateTime)e.Value; ok = employee.ChangeEndDate(start, end); } if (!ok) { MessageBox.Show("Даты отпуска пересекаются с уже существующим отпуском", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; } UpdateVacationInfo(); } } }
private void gvRooms_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e) { if (e.ColumnIndex == 1 || e.ColumnIndex == 3) // 1 should be your column index { int i; if (!int.TryParse(Convert.ToString(e.Value), out i)) { MessageBox.Show("Please enter numeric value"); e.Cancel = true; } } }
private void gridDepartments_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e) { if (e.RowIndex < 0) // Don't check if it's the new adding row { return; } switch (gridDepartments.CurrentColumn.Name) { case "DeptCode": string sCode = Helper.ConvertToString(e.Value); // Code cannot be empty if (sCode == string.Empty) { Helper.ShowError("Input the code for Department."); e.Cancel = true; } else { string oldCode = Helper.ConvertToString(e.OldValue); // If a new code is input if (sCode != oldCode) { Department currentDept = EQ_MainForm.dbContext.Departments.FirstOrDefault(d => d.DeptCode == sCode); if (currentDept != null) // Code is already existed { Helper.ShowError("The code is already existed. Input another code."); e.Cancel = true; } } } break; case "DeptName": // Name cannot be empty if (Helper.ConvertToString(e.Value) == string.Empty) { Helper.ShowError("Input the name of Department."); e.Cancel = true; } break; default: break; } }
private void gridUnits_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e) { if (e.RowIndex < 0) // Don't check if it's the new adding row { return; } /* switch (gridUnits.CurrentColumn.Name) * { * case "UCode": * string uCode = Helper.ConvertToString(e.Value); * // Code cannot be empty * if (uCode == string.Empty) * { * Helper.ShowError("Input the code for Unit."); * e.Cancel = true; * } * else * { * string oldCode = Helper.ConvertToString(e.OldValue); * // If a new code is input * if (uCode != oldCode) * { * Unit currentUnit = EQ_MainForm.dbContext.Units.FirstOrDefault(u => u.UCode == uCode); * if (currentUnit != null) // Code is already existed * { * Helper.ShowError("The code is already existed. Input another code."); * e.Cancel = true; * } * } * } * break; * case "UName": * // Name cannot be empty * if (Helper.ConvertToString(e.Value) == string.Empty) * { * Helper.ShowError("Input the name of Unit."); * e.Cancel = true; * } * break; * default: * break; * } */ }
private void gridEQCategory_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e) { if (e.RowIndex < 0) // Don't check if it's the new adding row { return; } //switch (gridEQCategory.CurrentColumn.Name) //{ // case "Code": // string eqcCode = Helper.ConvertToString(e.Value); // // Code cannot be empty // if (eqcCode == string.Empty) // { // Helper.ShowError("Input the code for Equipment Category."); // e.Cancel = true; // } // else // { // string oldCode = Helper.ConvertToString(e.OldValue); // // If a new code is input // if (eqcCode != oldCode) // { // EQ_Categories currentEQCategory = EQ_MainForm.dbContext.EQ_Categories.FirstOrDefault(eqc => eqc.Code == eqcCode); // if (currentEQCategory != null) // Code is already existed // { // Helper.ShowError("The code is already existed. Input another code."); // e.Cancel = true; // } // } // } // break; // case "Name": // // Name cannot be empty // if (Helper.ConvertToString(e.Value) == string.Empty) // { // Helper.ShowError("Input the name of Equipment Category."); // e.Cancel = true; // } // break; // default: // break; //} }