Exemplo n.º 1
0
        private void CreateBtn_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(TXT_PRICE.Text))
            {
                TXT_PRICE.Text = "0";
            }
            using (var context = new KhorshidContext())
            {
                var res = GetMArray(CMB_START.Text, CMB_END.SelectedIndex);
                foreach (var item in res)
                {
                    var service = new Service
                    {
                        DriveName     = _driver,
                        Name          = TXT_STU_NAME.Text,
                        Phone         = TXT_STU_PH.Text,
                        Adreess       = TXT_STU_ADD.Text,
                        SchoolName    = TXT_SC_NAME.Text,
                        SchoolPhone   = TXT_SC_PH.Text,
                        SchoolAdreess = TXT_SC_ADR.Text,
                        date          = item,
                        Price         = int.Parse(TXT_PRICE.Text.Replace(",", "")),
                        PricePay      = 0,
                    };


                    context.Services.Add(service);
                    context.SaveChanges();
                }
                App.Navigator.Navigate(new MyService(_driver));
            }
        }
Exemplo n.º 2
0
        public static void ApplySearchOnCollection(string term, ObservableCollection <Customer> collection)
        {
            var searchResult = new HashSet <Customer>();
            var context      = new KhorshidContext();
            var rawData      = context.Customers;

            var data = rawData.Select(item => new
            {
                item.Id,
                item.SubscriptionId,
                item.Address,
                item.MobileNumber,
                item.PhoneNumber,
                Name = item.Name.Replace("آ", "ا")
            }).ToList();

            if (int.TryParse(term, out int parsedTerm))
            {
                var desiredItem = rawData.FirstOrDefault(dataItem => dataItem.SubscriptionId == parsedTerm);
                if (desiredItem != null)
                {
                    searchResult.Add(desiredItem);
                }
            }

            data.Where(item =>
                       item.Name.StartsWith(term)
                       )
            .ToList()
            .ForEach(item =>
                     searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id))
                     );

            data.Where(item => item.Name.Split(' ').ToList().Any(tagItem => tagItem.StartsWith(term)))
            .ToList()
            .ForEach(item => searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id)));

            // Search by tokenizing terms
            var termSplit = term.Split(' ');

            if (termSplit.Length > 1)
            {
                data.Where(
                    townData =>
                {
                    string[] townSplit = townData.Name.Split(' ');
                    return(termSplit.ToList().TrueForAll(str => townSplit.Any(townItem => townItem.StartsWith(str))));
                }
                    )
                .ToList()
                .ForEach(item =>
                         searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id))
                         );
            }

            collection.Clear();
            searchResult.ToList().ForEach(item => collection.Add(item));
        }
Exemplo n.º 3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);
            using (var context = new KhorshidContext())
            {
                context.Database.Initialize(false);
            }

            CultureInfo.DefaultThreadCurrentCulture   = new CultureInfo("fa-IR");
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("fa-IR");
        }
Exemplo n.º 4
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            DataGrid_Main.DataContext = CustomerItems;

            var context = new KhorshidContext();

            CustomerItems.Clear();
            context.Customers.ToList().ForEach(c => CustomerItems.Add(c));

            SearchBox.Focus();
        }
Exemplo n.º 5
0
        public EditDriverPage(int driverId)
        {
            InitializeComponent();
            DriverId = driverId;

            var driver = new KhorshidContext().Drivers.First(d => d.Id == driverId);

            DataContext = new EditDriverViewModel
            {
                DriverDescription = driver.Description,
                DriverName        = driver.Name
            };
        }
Exemplo n.º 6
0
        private void AddItem_Button_Click(object sender, RoutedEventArgs e)
        {
            var context = new KhorshidContext();

            CurrentModifyId    = context.TownData.Max(item => item.Id) + 1;
            Town_TextBox.Text  = "";
            Price_Textbox.Text = "";
            Tags_Textbox.Text  = "";
            OkButton.Content   = "ساخت جدید";
            OkButton.Tag       = true;
            PopupTitle.Text    = "ایجاد ناحیه جدید";
            UI_Overlay.ShowUsingLinearAnimation(milliSeconds: 250);
        }
Exemplo n.º 7
0
        private void EditDriverButton_Click(object sender, RoutedEventArgs e)
        {
            var context = new KhorshidContext();

            if (context.Drivers.FirstOrDefault(d => d.Id == DriverId) is Driver driver)
            {
                driver.Name        = DriverName_Textbox.Text;
                driver.Description = Description_Textbox.Text;

                context.SaveChanges();
            }

            App.Navigator.Navigate(new DriverPage(DriverId));
        }
Exemplo n.º 8
0
        private void AddItem_Button_Click(object sender, RoutedEventArgs e)
        {
            var context = new KhorshidContext();

            Name_Textbox.Text                       =
                PhoneNumber_Textbox.Text            =
                    Mobile_Textbox.Text             =
                        SubscriptionId_Textbox.Text =
                            Address_Textbox.Text    = "";

            OkButton.Content = "ساخت جدید";
            OkButton.Tag     = true;
            PopupTitle.Text  = "ایجاد مشترک جدید";
            UI_Overlay.ShowUsingLinearAnimation(milliSeconds: 250);
        }
Exemplo n.º 9
0
        private void SearchTextBox_ApplyModification()
        {
            if (SearchBox.Text.Trim()?.Length == 0)
            {
                var context = new KhorshidContext();
                CustomerItems.Clear();
                context.Customers.ToList().ForEach(c => CustomerItems.Add(c));
            }
            else
            {
                string term = SearchBox.Text.Replace("آ", "ا");

                SearchEngine.ApplySearchOnCollection(term, CustomerItems);
            }
        }
Exemplo n.º 10
0
        private void DataGrid_Main_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var row = e.Row.DataContext as TownData;

            var context = new KhorshidContext();

            var data = context.TownData;

            var editedItem = data.Find(row.Id);

            editedItem.Price = row.Price.Replace(" تومان", "").Replace("تومان", "");
            editedItem.Tag   = row.Tag;
            editedItem.Town  = row.Town;

            context.SaveChanges();
        }
Exemplo n.º 11
0
        public DriverDetailsViewModel(int id, KhorshidContext context)
        {
            DriverId = id;
            Context  = context;

            Context.WorkPages.Load();

            CurrentDriver = Context.Drivers.FirstOrDefault(d => d.Id == DriverId);

            RequestLastPage();

            context.TownData.Load();
            Locations = context.TownData.Local;

            UpdateVm();
        }
Exemplo n.º 12
0
        private void DeleteConfirm_Yes_Click(object sender, RoutedEventArgs e)
        {
            if (DataGrid_Main.SelectedItem is TownData model)
            {
                var context = new KhorshidContext();

                var desiredItem = context.TownData.First(item => item.Id == model.Id);

                context.TownData.Remove(desiredItem);

                context.SaveChanges();
            }

            Delete_Popup.IsOpen = false;

            SearchTextBox_ApplyModification();
        }
Exemplo n.º 13
0
        private void CreateDlt_Click(object sender, RoutedEventArgs e)
        {
            foreach (var res in DataGrid_Main.SelectedItems)
            {
                if (res is Service model)
                {
                    var context = new KhorshidContext();

                    var desiredItem = context.Services.First(item => item.Id == model.Id);

                    context.Services.Remove(desiredItem);

                    context.SaveChanges();
                }
            }

            App.Navigator.Navigate(new MyService(driver));
        }
Exemplo n.º 14
0
        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            if (Town_TextBox.Text.Trim()?.Length == 0 &&
                Price_Textbox.Text.Trim()?.Length == 0)
            {
                return;
            }

            var context = new KhorshidContext();

            if (OkButton.Tag is bool isCreateMode)
            {
                if (isCreateMode)
                {
                    var townData = new TownData()
                    {
                        Price = Price_Textbox.Text,
                        Town  = Town_TextBox.Text,
                        Tag   = Tags_Textbox.Text
                    };

                    context.TownData.Add(townData);
                    context.SaveChanges();
                    SearchTextBox_ApplyModification();
                }
                else
                {
                    var townData = context.TownData.First(item => item.Id == CurrentModifyId);
                    townData.Town  = Town_TextBox.Text;
                    townData.Price = Price_Textbox.Text;
                    townData.Tag   = Tags_Textbox.Text;

                    context.SaveChanges();

                    SearchTextBox_ApplyModification();
                }
            }
            else
            {
                return;
            }

            UI_Overlay.HideUsingLinearAnimation(milliSeconds: 250);
        }
Exemplo n.º 15
0
        private void CreateDriver_Button_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new KhorshidContext())
            {
                var driver = new Driver
                {
                    Name        = (DriverName_Textbox.Text.Trim().Length == 0) ? "(بدون عنوان)" : DriverName_Textbox.Text,
                    Description = Description_Textbox.Text,
                };
                var workPage = new WorkPage
                {
                    Driver = driver
                };

                context.Drivers.Add(driver);
                context.WorkPages.Add(workPage);

                context.SaveChanges();
            }
            App.Navigator.Navigate(new DriversManagement());
        }
Exemplo n.º 16
0
        private void AddItem_Button_Click(object sender, RoutedEventArgs e)
        {
            if (!EligibleToModifyCollection())
            {
                return;
            }

            var context = new KhorshidContext();

            PopupTitle.Text = "افزودن کارکرد جدید";

            DatePicker.SelectedDate    = DateTime.Now;
            FromLocation_ComboBox.Text = "";
            ToLocation_ComboBox.Text   = "";
            Price_Textbox.Text         = "";

            OkButton.Content = "ساخت جدید";
            OkButton.Tag     = true;

            UI_Overlay.ShowUsingLinearAnimation(milliSeconds: 250);
        }
Exemplo n.º 17
0
        private void DeleteConfirm_Yes_Click(object sender, RoutedEventArgs e)
        {
            var context = new KhorshidContext();

            if (context.Drivers.FirstOrDefault(d => d.Id == DriverId) is Driver driver)
            {
                foreach (var workpage in context.WorkPages.Where(wp => wp.DriverId == driver.Id))
                {
                    var workItems = context.DriverWorks.Where(dw => dw.WorkPage.Id == workpage.Id);
                    context.DriverWorks.RemoveRange(workItems);
                    context.WorkPages.Remove(workpage);
                }

                context.Drivers.Remove(driver);
                context.SaveChanges();
            }

            Delete_Popup.IsOpen = false;

            App.Navigator.Navigate(new DriversManagement());
        }
Exemplo n.º 18
0
        private void DeleteConfirm_Yes_Click(object sender, RoutedEventArgs e)
        {
            if (!EligibleToModifyCollection())
            {
                return;
            }

            if (DataGrid_Main.SelectedItem is DriverWork model)
            {
                var context = new KhorshidContext();

                var desiredItem = context.DriverWorks.First(item => item.Id == model.Id);

                context.DriverWorks.Remove(desiredItem);

                context.SaveChanges();

                GetVm().UpdateVm();
            }

            Delete_Popup.IsOpen = false;
        }
Exemplo n.º 19
0
        public static void ApplySearchOnCollection(string term, ObservableCollection <TownData> collection)
        {
            var searchResult = new HashSet <TownData>();
            var context      = new KhorshidContext();
            var rawData      = context.TownData;

            var data = rawData.Select(item => new
            {
                item.Id,
                item.Price,
                item.Tag,
                Town = item.Town.Replace(")", "").Replace("(", "").Replace("-", "").Replace("آ", "ا")
            }).ToList();

            if (int.TryParse(term, out int parsedTerm))
            {
                var desiredItem = rawData.FirstOrDefault(dataItem => dataItem.Id == parsedTerm);
                if (desiredItem != null)
                {
                    searchResult.Add(desiredItem);
                }
            }

            data.Where(item =>
                       item.Town.StartsWith(term)
                       )
            .ToList()
            .ForEach(item =>
                     searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id))
                     );

            data.Where(item => item.Town.Split(' ').ToList().Any(tagItem => tagItem.StartsWith(term)))
            .ToList()
            .ForEach(item => searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id)));

            data.Where(
                item => item.Tag.Split(' ').ToList().Any(tagItem => tagItem.StartsWith(term))
                )
            .ToList()
            .ForEach(item =>
                     searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id))
                     );

            // Search by tokenizing terms
            var termSplit = term.Split(' ');

            if (termSplit.Length > 1)
            {
                data.Where(
                    townData =>
                {
                    string[] townSplit = townData.Town.Split(' ');
                    return(termSplit.ToList().TrueForAll(str => townSplit.Any(townItem => townItem.StartsWith(str))));
                }
                    )
                .ToList()
                .ForEach(item =>
                         searchResult.Add(rawData.First(dataItem => dataItem.Id == item.Id))
                         );
            }

            collection.Clear();
            searchResult.ToList().ForEach(item => collection.Add(item.ApplyModifications()));
        }
Exemplo n.º 20
0
        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            if (Name_Textbox.Text.Trim()?.Length == 0 &&
                SubscriptionId_Textbox.Text.Trim()?.Length == 0)
            {
                return;
            }

            if (!int.TryParse(SubscriptionId_Textbox.Text, out int intSubscriptionId))
            {
                MessageBox.Show(
                    messageBoxText: "مقداری که برای شماره اشتراک وارد شده باید عدد باشد. لطفا روی دکمه OK کلیک کرده و سپس مقدار شماره اشتراک را تصحیح کنید.",
                    caption: "خطا",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Exclamation,
                    defaultResult: MessageBoxResult.OK,
                    options: MessageBoxOptions.RtlReading);
                return;
            }

            var context = new KhorshidContext();

            if (OkButton.Tag is bool isCreateMode)
            {
                if (isCreateMode)
                {
                    if (context.Customers.Any(c => c.SubscriptionId == intSubscriptionId))
                    {
                        MessageBox.Show(
                            messageBoxText: "این شماره اشتراک قبلا استفاده شده است. لطفا از شماره اشتراک دیگری استفاده کنید.",
                            caption: "خطا",
                            button: MessageBoxButton.OK,
                            icon: MessageBoxImage.Exclamation,
                            defaultResult: MessageBoxResult.OK,
                            options: MessageBoxOptions.RtlReading);
                        return;
                    }

                    context.Customers.Add(new Customer
                    {
                        Name           = Name_Textbox.Text,
                        Address        = Address_Textbox.Text,
                        MobileNumber   = Mobile_Textbox.Text,
                        PhoneNumber    = PhoneNumber_Textbox.Text,
                        SubscriptionId = intSubscriptionId
                    });

                    context.SaveChanges();
                    SearchTextBox_ApplyModification();
                }
                else
                {
                    var customer = context.Customers.First(item => item.Id == CurrentModifyId);

                    if (intSubscriptionId != customer.SubscriptionId &&
                        context.Customers.Any(c => c.SubscriptionId == intSubscriptionId))
                    {
                        MessageBox.Show(
                            messageBoxText: "این شماره اشتراک قبلا استفاده شده است. لطفا از شماره اشتراک دیگری استفاده کنید.",
                            caption: "خطا",
                            button: MessageBoxButton.OK,
                            icon: MessageBoxImage.Exclamation,
                            defaultResult: MessageBoxResult.OK,
                            options: MessageBoxOptions.RtlReading);
                        return;
                    }

                    customer.Name           = Name_Textbox.Text;
                    customer.Address        = Address_Textbox.Text;
                    customer.MobileNumber   = Mobile_Textbox.Text;
                    customer.PhoneNumber    = PhoneNumber_Textbox.Text;
                    customer.SubscriptionId = intSubscriptionId;

                    context.SaveChanges();

                    SearchTextBox_ApplyModification();
                }
            }
            else
            {
                return;
            }

            UI_Overlay.HideUsingLinearAnimation(milliSeconds: 250);
        }