void EditBizObject() { BizObject = null; int id; int.TryParse(gridDrivers.SelectedCells.First().RowInfo.Cells["Id"].Value.ToString(), out id); UpdateGrid(); Models.Driver DriverToEdit = TaxiDbContext.Instance.Users.OfType <Models.Driver>().Include(u => u.Car).SingleOrDefault(c => c.Id == (int)id && c.Role == Roles.Driver); if (DriverToEdit != null) { //BizObject = (Models.Driver)DriverToEdit.Clone(); BizObject = (Models.Driver)DriverToEdit.Clone(); txtSharePercent.Text = BizObject.SharePercent.ToString(); } }
void UpdateDriver() { Models.Driver Driver = (Models.Driver)TaxiDbContext.Instance.Users.Single(d => d.Id == BizObject.Id); //Driver = BizObject; Driver.FullName = BizObject.FullName; Driver.Mobile = BizObject.Mobile; Driver.SharePercent = BizObject.SharePercent; Driver.Car.Color = BizObject.Car.Color; Driver.Car.Model = BizObject.Car.Model; Driver.Car.LicensePlate1 = BizObject.Car.LicensePlate1; Driver.Car.LicensePlate2 = BizObject.Car.LicensePlate2; Driver.Car.LicensePlate3 = BizObject.Car.LicensePlate3; Driver.Car.LicensePlate4 = BizObject.Car.LicensePlate4; BizObject.IsDeleted = false; TaxiDbContext.Instance.SaveChanges(); BizObject = null; MessageBoxRTL.Info(".راننده با موفقیت ویرایش شد", string.Empty); UpdateGrid(); }
public frmDrivers() { btnDrivers.ChangeMenuItemImage(Properties.Resources.Drivers_out); InitializeComponent(); if (TaxiDbContext.Instance.Users.OfType <Models.Driver>().Any()) { UpdateGrid(); } BizObject = null; BizObject = new Models.Driver() { Id = 0, FullName = string.Empty, Mobile = string.Empty, SharePercent = 0, DateJoined = DateTime.Today, Car = new Models.Car() { Color = string.Empty, LicensePlate1 = string.Empty, LicensePlate2 = string.Empty, LicensePlate3 = string.Empty, LicensePlate4 = string.Empty, Model = string.Empty } }; gridDrivers.CellClick += gridDrivers_CellClick; comboboxCarModel.Items.AddRange(CarsList.Cars.Select(c => c.Model).ToArray()); var CarsColors = CarsList.Cars.First().Colors.Select(c => c.Title).ToArray(); comboboxCarColor.Items.AddRange(CarsColors); lblDateJoined.Text = DateTime.Today.ToPersianDateString(); }
void DeleteBizObject() { Models.Driver DriverToRemove = TaxiDbContext.Instance.Users.Find(int.Parse(gridDrivers.CurrentRow.Cells["Id"].Value.ToString())) as Models.Driver; DialogResult dr = MessageBoxRTL.Ask("آیا از حذف راننده اطمینان دارید؟", string.Empty); if (dr == DialogResult.OK) { try { //TaxiDbContext.Instance.Users.Remove(DriverToRemove); DriverToRemove.IsDeleted = true; TaxiDbContext.Instance.SaveChanges(); MessageBoxRTL.Info(".راننده با موفقیت حذف شد", string.Empty); UpdateGrid(); BizObject = null; } catch { MessageBoxRTL.Error("حذف راننده با خطا روبرو شد", string.Empty); } } }
private void btnCancel_Click(object sender, EventArgs e) { BizObject = null; }
private void btnSave_Click(object sender, EventArgs e) { int SharePercent = 0; int.TryParse(txtSharePercent.Text.PersianToEnglish(), out SharePercent); if (BizObject != null && !BizObject.IsDeleted) { BizObject.SharePercent = SharePercent; } if (BizObject != null && Validation.Validate(BizObject)) { if (!LicensePlateCalculation.IsCompelete(BizObject.Car)) { return; } try { if (BizObject.Id != 0) { UpdateDriver(); } else if (BizObject.Id == 0) { //if(TaxiDbContext.Instance.Users.OfType<Models.Driver>().Any(u => u.Mobile == BizObject.Mobile)) //avoid repeating Driver Mobile if (TaxiDbContext.Instance.Users.Any(u => u.Mobile == BizObject.Mobile && u.FullName != BizObject.FullName)) { MessageBoxRTL.Error("شماره همراه قبلا ثبت شده است. لطفا شماره دیگری وارد کنید", string.Empty); return; } if (TaxiDbContext.Instance.Users.Any(u => u.Mobile == BizObject.Mobile && u.FullName == BizObject.FullName)) { DialogResult dr = MessageBoxRTL.Ask("این راننده قبلا ثبت شده است. آیا مایل به ویرایش آن هستید؟", string.Empty); if (dr == DialogResult.OK) { Models.Driver CheckExistingDriver = TaxiDbContext.Instance.Users .OfType <Models.Driver>().Single(u => u.Mobile == BizObject.Mobile && u.FullName == BizObject.FullName); BizObject = null; BizObject = CheckExistingDriver; BizObject.SharePercent = SharePercent; UpdateDriver(); return; } return; } BizObject.SharePercent = SharePercent; BizObject.Role = Roles.Driver; TaxiDbContext.Instance.Users.Add(BizObject); TaxiDbContext.Instance.SaveChanges(); MessageBoxRTL.Info(".راننده با موفقیت افزوده شد", string.Empty); UpdateGrid(); BizObject = null; } } catch { MessageBoxRTL.Error("ذخیره سازی راننده با خطا روبرو شد.", string.Empty); } } }