Esempio n. 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (BizObject != null && Validation.Validate(BizObject))
     {
         try
         {
             if (BizObject.Id != 0)
             {
                 Models.Customer Customer = (Models.Customer)TaxiDbContext.Instance.Users.Find(BizObject.Id);
                 Customer.FullName = BizObject.FullName;
                 Customer.Mobile   = BizObject.Mobile;
                 Customer.Address  = BizObject.Address;
                 TaxiDbContext.Instance.SaveChanges();
                 BizObject = null;
                 MessageBoxRTL.Info(".مشتری با موفقیت ویرایش شد", string.Empty);
                 UpdateGrid();
             }
             else if (BizObject.Id == 0)
             {
                 BizObject.Role       = Roles.Customer;
                 BizObject.DateJoined = DateTime.Today;
                 TaxiDbContext.Instance.Users.Add(BizObject);
                 TaxiDbContext.Instance.SaveChanges();
                 MessageBoxRTL.Info(".مشتری با موفقیت افزوده شد", string.Empty);
                 UpdateGrid();
             }
             BizObject = null;
         }
         catch
         {
             MessageBoxRTL.Error("ذخیره سازی مشتری با خطا روبرو شد.", string.Empty);
         }
     }
 }
Esempio n. 2
0
 private void btnRegister_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtSecurityQuestion.Text) || string.IsNullOrEmpty(txtSecurityAnswer.Text))
     {
         MessageBoxRTL.Error("وارد کردن سوال امنیتی و پاسخ آن ضروری است", string.Empty);
         return;
     }
     if (!TaxiDbContext.Instance.AuthenticatedUsers.Any())
     {
         AuthenticatedUser user = new AuthenticatedUser()
         {
             FullName         = txtFullName.Text,
             Mobile           = txtMobile.Text.PersianToEnglish(),
             Username         = txtUsername.Text,
             Password         = EasyHash.Hash(txtPassword.Text),
             Role             = Roles.Admin,
             SecurityQuestion = txtSecurityQuestion.Text,
             SecurityAnswer   = EasyHash.Hash(txtSecurityAnswer.Text),
             DateJoined       = DateTime.Today
         };
         if (Validation.Validate(user) & Validation.ValidatePassword(txtPassword.Text))
         {
             TaxiDbContext.Instance.AuthenticatedUsers.Add(user);
             TaxiDbContext.Instance.SaveChanges();
             Utility.MessageBoxRTL.Info("ثبت نام مدیر با موفقیت انجام شد.اکنون می‌توانید وارد حساب کاربری‌تان شوید.", "ثبت نام");
             this.Hide();
             new Login();
             Session.RecentlyLogedIn = true;
         }
     }
 }
Esempio n. 3
0
 protected override void btnRestorePassword_Click(object sender, EventArgs e)
 {
     if (TaxiDbContext.Instance.AuthenticatedUsers.Any(u => u.Username == txtUsername.Text))
     {
         new PasswordForgetion(txtUsername.Text);
     }
     else
     {
         MessageBoxRTL.Error("کاربری با این مشخصات یافت نشد", string.Empty);
     }
 }
Esempio n. 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            BizObject.TaxiName = TaxiDbContext.Instance.AuthenticatedUsers.Where(u => u.Role == Roles.Admin).First().TaxiName;
            if (BizObject != null && Validation.Validate(BizObject))
            {
                try
                {
                    if (BizObject.Id != 0)
                    {
                        UpdateSecretary();
                    }
                    else if (BizObject.Id == 0)
                    {
                        //avoid repeating Secretary 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.AuthenticatedUser CheckExistingSecretary = TaxiDbContext.Instance.Users
                                                                                  .OfType <Models.AuthenticatedUser>().Single(u => u.Mobile == BizObject.Mobile &&
                                                                                                                              u.FullName == BizObject.FullName);
                                BizObject = null;
                                BizObject = CheckExistingSecretary;
                                UpdateSecretary();
                                return;
                            }
                            return;
                        }
                        BizObject.Role     = Roles.Secretary;
                        BizObject.TaxiName = TaxiDbContext.Instance.AuthenticatedUsers.Where(u => u.Role == Roles.Admin).First().TaxiName;
                        BizObject.Password = EasyHash.Hash(txtSecretaryPassword.Text);
                        TaxiDbContext.Instance.Users.Add(BizObject);
                        TaxiDbContext.Instance.SaveChanges();
                        MessageBoxRTL.Info(".منشی با موفقیت افزوده شد", string.Empty);
                        UpdateGrid();
                        BizObject = null;
                    }
                }
                catch
                {
                    MessageBoxRTL.Error("ذخیره سازی منشی با خطا روبرو شد.", string.Empty);
                }
            }
        }
Esempio n. 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int cost = 0;

            int.TryParse(txtCost.Text.PersianToEnglish(), out cost);
            if (BizObject != null && !BizObject.IsDeleted)
            {
                BizObject.Cost = cost;
            }
            if (BizObject != null && Validation.Validate(BizObject))
            {
                try
                {
                    if (BizObject.Id != 0)
                    {
                        UpdatePath();
                    }
                    else if (BizObject.Id == 0)
                    {
                        var CheckExistingPath = TaxiDbContext.Instance.Paths
                                                .SingleOrDefault(p => p.Origin == BizObject.Origin && p.Destination == BizObject.Destination);
                        if (CheckExistingPath != null)
                        {
                            DialogResult dr = MessageBoxRTL.Ask("این مسیر قبلا ثبت شده است. آیا تمایل به ویرایش آن دارید؟", string.Empty);
                            if (dr == DialogResult.OK)
                            {
                                BizObject      = null;
                                BizObject      = CheckExistingPath;
                                BizObject.Cost = cost;
                                UpdatePath();
                                return;
                            }
                            else
                            {
                                return;
                            }
                        }
                        BizObject.Cost = cost;
                        TaxiDbContext.Instance.Paths.Add(BizObject);
                        TaxiDbContext.Instance.SaveChanges();
                        MessageBoxRTL.Info(".مسیر با موفقیت افزوده شد", string.Empty);
                        UpdateGrid();
                    }
                    BizObject = null;
                }
                catch
                {
                    MessageBoxRTL.Error("ذخیره سازی مسیر با خطا روبرو شد.", string.Empty);
                }
            }
        }
Esempio n. 6
0
        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 btnChangePassword_Click(object sender, EventArgs e)
 {
     if (txtPassword.Text == txtPasswordRepeation.Text && Validation.ValidatePassword(txtPassword.Text))
     {
         user.Password = EasyHash.Hash(txtPassword.Text);
         try
         {
             TaxiDbContext.Instance.AuthenticatedUsers.AddOrUpdate(user);
             TaxiDbContext.Instance.SaveChanges();
             MessageBoxRTL.Info("کلمه عبور شما با موفقیت تغییر یافت.", string.Empty);
             this.Close();
         }
         catch
         {
             MessageBoxRTL.Error("عملیات تغییر کلمه عبور موفقیت آمیز نبود. لطفا مجددا تلاش نمایید.", "خطا");
         }
     }
     else
     {
         MessageBoxRTL.Error("کلمه عبور باید حداقل 8 کاراکتر شامل حداقل یک حرف بزرگ، یک حرف کوچک و یک عدد باشد", "خطا");
     }
 }
Esempio n. 8
0
        void DeleteBizObject()
        {
            Models.Service ServiceToRemove = db.Services.Find(int.Parse(gridServices.CurrentRow.Cells["Id"].Value.ToString()));
            DialogResult   dr = MessageBoxRTL.Ask("آیا از حذف سرویس اطمینان دارید؟", string.Empty);

            if (dr == DialogResult.OK)
            {
                try
                {
                    ServiceToRemove.IsDeleted = true;
                    db.SaveChanges();
                    MessageBoxRTL.Info(".سرویس با موفقیت حذف شد", string.Empty);
                    ClearForm();
                    UpdateGrid();
                    BizObject = null;
                }
                catch
                {
                    MessageBoxRTL.Error("حذف سرویس با خطا روبرو شد", string.Empty);
                }
            }
        }
Esempio n. 9
0
        void DeleteBizObject()
        {
            Models.Path  PathToRemove = TaxiDbContext.Instance.Paths.Find(gridPaths.CurrentRow.Cells["Id"].Value);
            DialogResult dr           = MessageBoxRTL.Ask("آیا از حذف مسیر اطمینان دارید؟", string.Empty);

            if (dr == DialogResult.OK)
            {
                try
                {
                    //TaxiDbContext.Instance.Paths.Remove(PathToRemove);
                    PathToRemove.IsDeleted = true;
                    TaxiDbContext.Instance.SaveChanges();
                    MessageBoxRTL.Info(".مسیر با موفقیت حذف شد", string.Empty);
                    UpdateGrid();
                }
                catch
                {
                    MessageBoxRTL.Error("حذف مسیر با خطا روبرو شد", string.Empty);
                }
            }
            BizObject = null;
        }
Esempio n. 10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (BizObject != null)
            {
                try
                {
                    if (ServiceToEdit != null && ServiceToEdit.Id != 0)
                    {
                        //BizObject = (Models.Driver)DriverToEdit.Clone();
                        //BizObject = (Models.Service)ServiceToEdit.Clone();

                        //Models.Service Service = (Models.Service)db.Services
                        //    .Single(d => d.Id == BizObject.Id);

                        using (TaxiDbContext taxiDb = new TaxiDbContext())
                        {
                            Models.Service service = taxiDb.Services.Find(ServiceToEdit.Id);
                            service.DriverId = taxiDb.Users.OfType <Models.Driver>()
                                               .SingleOrDefault(d => d.FullName == comboboxDrivers.Text).Id;

                            var NewPath = taxiDb.Paths.SingleOrDefault(p => p.OriginDestination == comboboxPaths.Text);
                            service.ServicePaths.First().PathId = NewPath.Id;

                            service.Transaction.Amount = NewPath.Cost;
                            service.Transaction.IsPaid = checkboxIsPaid.Checked;

                            if (taxiDb.Users.OfType <Models.Customer>().Any(c => c.FullName == txtCustomerName.Text))
                            {
                                service.CustomerId =
                                    taxiDb.Users.OfType <Models.Customer>().Single(c => c.FullName == txtCustomerName.Text).Id;
                            }
                            else
                            {
                                service.Customer = new Models.Customer()
                                {
                                    Role     = Models.Roles.Customer,
                                    FullName = txtCustomerName.Text,
                                    Mobile   = txtCustomerPhone.Text,
                                    Address  = "ثبت نشده"
                                };
                            }


                            taxiDb.SaveChanges();
                        }

                        db = new TaxiDbContext();

                        BizObject = null;
                        MessageBoxRTL.Info(".سرویس با موفقیت ویرایش شد", string.Empty);
                        ClearForm();
                    }
                    else if (BizObject.Id == 0)
                    {
                        using (TaxiDbContext taxiDb = new TaxiDbContext())
                        {
                            if (string.IsNullOrEmpty(txtCustomerName.Text))
                            {
                                MessageBoxRTL.Error("نام مشتری ضروری است.", string.Empty);
                                txtCustomerName.Focus();
                                return;
                            }
                            if (string.IsNullOrEmpty(txtCustomerPhone.Text) &&
                                !txtCustomerPhone.Text.StartsWith("09") &&
                                txtCustomerPhone.Text.Length != 11)
                            {
                                MessageBoxRTL.Error("شماره همراه مشتری ضروری است. و با 09 آغاز می‌شود", string.Empty);
                                txtCustomerPhone.Focus();
                                return;
                            }
                            if (string.IsNullOrEmpty(comboboxDrivers.Text))
                            {
                                MessageBoxRTL.Error("نام راننده ضروری است.", string.Empty);
                                comboboxDrivers.Focus();
                                return;
                            }
                            if (string.IsNullOrEmpty(comboboxPaths.Text))
                            {
                                MessageBoxRTL.Error("مسیر ضروری است.", string.Empty);
                                comboboxPaths.Focus();
                                return;
                            }

                            //avoid adding a new customer with different name but exisiting phone -- TWO Customer With Same Phone
                            if (taxiDb.Users.OfType <Models.Customer>().Any(c => c.Mobile == txtCustomerPhone.Text && c.FullName != txtCustomerName.Text))
                            {
                                MessageBoxRTL.Error("شماره همراه مشتری قبلا ثبت شده است. لطفا شماره دیگری وارد نمایید", string.Empty);
                                txtCustomerPhone.Focus();
                                return;
                            }

                            BizObject.Customer = taxiDb.Users.OfType <Models.Customer>().SingleOrDefault(c => c.Mobile == txtCustomerPhone.Text);

                            if (BizObject.Customer == null)
                            {
                                BizObject.Customer = new Models.Customer()
                                {
                                    FullName = txtCustomerName.Text,
                                    Mobile   = txtCustomerPhone.Text,
                                    Address  = "ثبت نشده",
                                    Role     = Models.Roles.Customer
                                };
                            }

                            //driver
                            if (!comboboxDrivers.Items.Contains(comboboxDrivers.Text))
                            {
                                MessageBoxRTL.Error("راننده‌ای با این مشخصات وجود ندارد", string.Empty);
                                comboboxDrivers.Focus();
                                return;
                            }

                            BizObject.Driver = taxiDb.Users.OfType <Models.Driver>()
                                               .SingleOrDefault(d => d.FullName == comboboxDrivers.Text);

                            //path
                            if (!comboboxPaths.Items.Contains(comboboxPaths.Text))
                            {
                                MessageBoxRTL.Error("مسیری با این مشخصات وجود ندارد", string.Empty);
                                comboboxPaths.Focus();
                                return;
                            }

                            BizObject.ServicePaths = new List <Models.ServicePath>();
                            var NewPath = taxiDb.Paths
                                          .SingleOrDefault(p => p.OriginDestination == comboboxPaths.Text);
                            BizObject.ServicePaths.Add(new Models.ServicePath()
                            {
                                Path = NewPath
                            });

                            BizObject.Transaction.IsPaid = checkboxIsPaid.Checked;
                            BizObject.Transaction.Amount = NewPath.Cost;

                            BizObject.OriginInDetail      = txtOriginInDetail.Text;
                            BizObject.DestinationInDetail = txtDestinationInDetail.Text;

                            BizObject.DateTime = DateTime.Now;

                            int Delay = 0;
                            int.TryParse(txtDelay.Text, out Delay);
                            BizObject.Delay = Delay;

                            BizObject.IsActive  = true;
                            BizObject.IsDeleted = false;


                            taxiDb.Services.Add(BizObject);
                            taxiDb.SaveChanges();
                        }
                        db        = new TaxiDbContext();
                        BizObject = null;

                        MessageBoxRTL.Info(".سرویس با موفقیت افزوده شد", string.Empty);
                        ClearForm();
                    }
                }
                catch
                {
                    MessageBoxRTL.Error("ذخیره سازی سرویس با خطا روبرو شد.", string.Empty);
                }
            }
        }
Esempio n. 11
0
        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);
                }
            }
        }