예제 #1
0
 public static List <ContactDetails> GetCustomerNumbers(int id)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             Dictionary <string, object> p = new Dictionary <string, object>
             {
                 { "@Id", id }
             };
             string query = "SELECT Id, CustomerId, ContactTypeId, ContactInfo " +
                            "FROM CustomerContactDetails " +
                            "WHERE CustomerId = @Id";
             con.Open();
             return(DBActions.ExecReaderListQR <ContactDetails>(con, query, p));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(null);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #2
0
 public static int UpdateCustomer(Customer c)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             Dictionary <string, object> p = new Dictionary <string, object>
             {
                 { "@Id", c.Id },
                 { "@FirstName", c.FirstName },
                 { "@LastName", c.LastName },
                 { "@DateOfBirth", c.DateOfBirth },
                 { "@CompanyId", c.CompanyId }
             };
             con.Open();
             return(DBActions.ExecNonReaderSP(con, "updateCustomerByID", p));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(-1);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #3
0
 public static List <AddressVM> GetCustomerAddressList(int id)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             Dictionary <string, object> p = new Dictionary <string, object>
             {
                 { "@Id", id }
             };
             string query = "SELECT Id, Road, Number, City, Region, State, PostalCode, Country " +
                            "FROM CustomerAddress " +
                            "WHERE CustomerId = @Id";
             con.Open();
             return(DBActions.ExecReaderListQR <AddressVM>(con, query, p));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(null);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #4
0
 public static int AddCustomerNumber(ContactDetails number)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             int retVal = -1;
             Dictionary <string, object> inParams = new Dictionary <string, object>
             {
                 { "@CustomerId", number.CustomerId },
                 { "@ContactTypeId", number.ContactTypeId },
                 { "@ContactInfo", number.ContactInfo }
             };
             Dictionary <string, object> outParams = new Dictionary <string, object>
             {
                 { "@NewId", -1 }
             };
             con.Open();
             retVal = (int)DBActions.ExecNonReaderWithReturnSP(con, "addCustomerNumber", inParams, outParams);
             return(retVal);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(-1);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #5
0
        private async void ButtonRemove(object s, EventArgs args)
        {
            if (clicked)
            {
                return;
            }
            if (admin != null)
            {
                clicked = true;
                var b = await App.Send("Meddelande",
                                       "Vill du också radera alla tillhörande produkter?", "Ja", "Nej", ManagePage.page);

                await DBActions.FullyRemoveAdmin(admin);

                if (b)
                {
                    var a = DBActions._a(admin);
                    foreach (Products p in a)
                    {
                        await DBActions.FullyRemoveProduct(p);
                    }
                }
                search.Text = null;
                App.Send("Info", "Kontot med ID: " + admin.ID + " har raderats!", "Ok", ManagePage.page);
                stack.IsVisible = false;
                clicked         = false;
            }
        }
예제 #6
0
        public DBActions InsertOrUpdate(Person newPerson)
        {
            DBActions action = DBActions.None;

            using (var dao = new PersonLINQDao())
            {
                var thePerson = dao.Persons.Find(newPerson.Id);
                action = thePerson != null ? DBActions.Update : DBActions.Insert;

                switch (action)
                {
                case DBActions.Insert:
                    //newPerson.Id = 0;
                    newPerson.Intime = DateTime.Now;
                    newPerson.Utime  = DateTime.Now;
                    newPerson.Id     = Convert.ToInt32(dao.InsertWithIdentity(newPerson));
                    break;

                case DBActions.Update:
                    newPerson.Intime = thePerson.Intime;
                    newPerson.Utime  = DateTime.Now;
                    dao.Update(newPerson);
                    break;
                }
            }

            return(action);
        }
예제 #7
0
 public static int AddCustomer(Customer c)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             int retVal = -1;
             Dictionary <string, object> inParams = new Dictionary <string, object>
             {
                 { "@FirstName", c.FirstName },
                 { "@LastName", c.LastName },
                 { "@DateOfBirth", c.DateOfBirth },
                 { "@CompanyId", c.CompanyId },
             };
             Dictionary <string, object> outParams = new Dictionary <string, object>
             {
                 { "@NewId", -1 }
             };
             con.Open();
             retVal = (int)DBActions.ExecNonReaderWithReturnSP(con, "createNewCustomer", inParams, outParams);
             return(retVal);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(-1);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #8
0
        private void OnSearch()
        {
            var text = search.Text;

            if (text != null)
            {
                var ad = DBActions.GetAdminById(text);
                if (ad != null)
                {
                    if (ad.ID == App.ACCOUNT_NAME)
                    {
                        return;
                    }
                    admin           = ad;
                    stack.IsVisible = true;
                }
                else
                {
                    stack.IsVisible = false;
                    App.Send("Fel", "Kunde inte hitta kontot med ID: " + text + "!", "Avbryt", ManagePage.page);
                }
            }
            else
            {
                App.Send("Fel", "Ange admin id!", "Avbryt", ManagePage.page);
            }
        }
예제 #9
0
 public static int DeleteCustomerAddresses(int id)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             Dictionary <string, object> p = new Dictionary <string, object>
             {
                 { "@Id", id }
             };
             string cmdText = "DELETE " +
                              "FROM CustomerAddress " +
                              "WHERE CustomerId = @Id";
             con.Open();
             return(DBActions.ExecNonReaderQR(con, cmdText, p));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(-1);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #10
0
        private async void LoadContent()
        {
            ImageSource src  = null;
            ImageSource src1 = null;
            AdminIcon   ai   = await DBActions.LoadAdminIcon(DBActions._p(binary.PRODUCT));

            Images img = await DBActions.LoadProductImage(binary.PRODUCT);

            if (ai != null)
            {
                src = App.ByteToImage(ai.Image);
            }
            else
            {
                src = App.GetSource("icon-blank.png");
            }
            if (img != null)
            {
                src1 = App.ByteToImage(img.Image);
            }
            else
            {
                src1 = App.GetSource("noproduct.jpg");
            }
            icon.SetSRC(src);
            product_image.SetSRC(src1);
            content_loading.IsVisible = false;
            animation.Pause();
            LOADING = false;
        }
예제 #11
0
        private void Login_Cliked(object sender, EventArgs e)
        {
            string u = e_name.Text;
            string p = e_pass.Text;

            if (u != null && p != null)
            {
                Accounts a = DBActions.GetAccountByName(u);
                if (a != null && a.DPassword == p)
                {
                    if (a.DUType == 0)
                    {
                        Navigation.PushAsync(new Startsidan());
                        App.Current.Properties["LoggedUser"] = a.DUsername;
                        App.Current.SavePropertiesAsync();
                    }
                    else
                    {
                        //TODO
                        //Restaurant Page
                    }
                }
                else
                {
                    DisplayAlert("Misslyckad Inloggning", "Ogiltigt användernamn eller lösenord!", "Avbryt");
                }
            }
            else
            {
                DisplayAlert("Misslyckad Inloggning", "Mata in ditt användernamn och lösenord", "Okej");
            }
        }
예제 #12
0
 public static Company GetCompany(int?id)
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             if (id is null)
             {
                 return(null);
             }
             Dictionary <string, object> p = new Dictionary <string, object>
             {
                 { "@Id", id }
             };
             string query = "SELECT Id, Name, Title, Country " +
                            "FROM Companies " +
                            "WHERE Id = @Id";
             con.Open();
             return(DBActions.ExecReaderQR <Company>(con, query, p));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(null);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #13
0
 private async void ShowProduct(object s, EventArgs a)
 {
     if (await DBActions.Check(MapPage._g as Admins, MapPage.mapPage))
     {
         return;
     }
     MapPage.mapPage.OpenProduct(binary);
 }
예제 #14
0
        private async void RCommand1()
        {
            await DBActions.LoadProducts();

            await DBActions.LoadUsers();

            events.rel_admin(search1.Text);
            refr1.IsRefreshing = false;
        }
예제 #15
0
 protected override void AddItem()
 {
     DBActions.Add <Storage>(new Storage
     {
         Name = "Новый элемент" + ListCurrentData.Count
     });
     ListCurrentData = DBActions.Get <Storage>();
     OnPropertyChanged("ListCurrentData");
     SelectedDataItem = ListCurrentData[ListCurrentData.Count - 1];
 }
        protected override void AddItem()
        {
            DBActions.Add <Provider>(new Provider
            {
                FullName = "Поставщик новый " + ListCurrentData.Count
            });

            ListCurrentData = DBActions.Get <Provider>();
            OnPropertyChanged("ListCurrentData");
            SelectedDataItem = ListCurrentData[ListCurrentData.Count - 1];
        }
예제 #17
0
        protected override void AddItem()
        {
            DBActions.Add <Client>(new Client
            {
                FullName = "Поставщик клиент " + ListCurrentData.Count
            });

            ListCurrentData = DBActions.Get <Client>();
            OnPropertyChanged("ListCurrentData");
            SelectedDataItem = ListCurrentData[ListCurrentData.Count - 1];
        }
예제 #18
0
        private async void RCommand()
        {
            await DBActions.LoadAdmins();

            await DBActions.LoadProducts();

            await DBActions.LoadUsers();

            events.rel(TXT());
            refr.IsRefreshing = false;
        }
예제 #19
0
        private async void ButtonClicked(object s, EventArgs a)
        {
            if (loading)
            {
                return;
            }
            var x = loc.Text; var x1 = name.Text; var x2 = email.Text; var x3 = phone.Text;

            loading = true;
            if (file == null)
            {
                DisplayAlert("Fel", "Välj en ikon!", "Avbryt");
                loading = false;
                return;
            }
            if (x != null && x1 != null && x2 != null && x3 != null)
            {
                an.IsVisible = true;
                an.Play();
                var list = await App.GetPositions(x);

                if (list.Count == 1)
                {
                    _a.Address = await App.GetAddress(list[0]);

                    _a.SName = x1; _a.Email = x2; _a.Phone = x3; _a.Login = true;
                    await DBActions.EditAdmin(_a);

                    var aicon = new AdminIcon {
                        ID = _a.ID, Image = App.ImageToByte(file)
                    };
                    if (hadAdminIcon)
                    {
                        await DBActions.EditAdminIcon(aicon);
                    }
                    else
                    {
                        await DBActions.AddAdminIcon(aicon);
                    }
                    await App.ReloadPins();

                    an.IsVisible = false;
                    an.Pause();
                    Navigation.PushAsync(new MapPage(_a));
                    App.RemovePage(this);
                    return;
                }
            }
            an.IsVisible = false;
            an.Pause();
            loading = false;
            await DisplayAlert("Fel", "Ange en giltig adress!", "Avbryt");
        }
예제 #20
0
        public CardDefault(Binary b)
        {
            this.b = b;
            InitializeComponent();
            Account acc = MapPage._g;

            if (acc is Guests)
            {
                Guests g = acc as Guests;
                if (!DBActions.hasBooked(g, b.PRODUCT))
                {
                    btn.Text = "RESERVERA";
                }
            }
            lbl.Text     = b.PRODUCT.Description;
            btn.Clicked += async(s, e) => {
                if (loading)
                {
                    return;
                }
                if (MapPage._g is Admins)
                {
                    if (await DBActions.Check(MapPage._g as Admins, MapPage.mapPage))
                    {
                        return;
                    }
                }
                loading = true;
                await DBActions.LoadProducts();

                await DBActions.LoadUsers();

                var prds = DBActions.GetProductById(b.PRODUCT.ID);
                if (prds != null && prds.Quantity > 0 &&
                    DBActions.GetAdminById(prds.AdminID) != null)
                {
                    MapPage.mapPage.OpenProduct(b);
                }
                else
                {
                    App.Send("Info", "Produkten finns inte längre!", "Ok");
                    if (DBActions.GetAdminById(prds.AdminID) == null)
                    {
                        await DBActions.CheckProducts();
                    }
                    MapPage.mapPage.ReloadAll();
                }
                loading = false;
            };
        }
예제 #21
0
        private async void SetIcon()
        {
            var v = await DBActions.LoadAdminIcon(_a);

            if (v != null)
            {
                hadAdminIcon = true;
                icon.Source  = App.ByteToImage(v.Image);
            }
            else
            {
                icon.Source = App.GetSource("icon.png");
            }
        }
예제 #22
0
        private async void Ask()
        {
            var l = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

            if (l != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.LocationWhenInUse });

                if (results.ContainsKey(Permission.LocationWhenInUse))
                {
                    l = results[Permission.LocationWhenInUse];
                }
            }
            if (l == PermissionStatus.Granted)
            {
                // Load Database
                if (App.Current.Properties.ContainsKey("LoggedUser") &&
                    DBActions.GetAccountByName(App.Current.Properties["LoggedUser"] as string) != null)
                {
                    Accounts acc = DBActions.GetAccountByName(App.Current.Properties["LoggedUser"] as string);
                    if (acc.DUType == 0)
                    {
                        Navigation.PushAsync(new Startsidan());
                    }
                    else
                    {
                        // Restaurant Page
                        //Navigation.PushAsync();
                    }
                }
                else
                {
                    //Navigation.PushAsync(new RestaurantPage());
                    Navigation.PushAsync(new MenuDisplayPage());
                    //Navigation.PushAsync(new MenusPage());
                    //Navigation.PushAsync(new Startsidan());
                    //Navigation.PushAsync(new WelcomePage());
                    //Navigation.PushAsync(new PaymentPage());
                }
            }
            else
            {
                //var x = await DisplayAlert("Error", "You must allow location access!", "Retry", "Cancel");
                //if (x)
                //{
                Ask();
                //}
            }
        }
예제 #23
0
        private async void Load()
        {
            Images images = await DBActions.LoadProductImage(b.PRODUCT);

            if (images != null)
            {
                img.Source = App.ByteToImage(images.Image);
            }
            else
            {
                img.Source = App.GetSource("noimage.png");
            }
            image_loading.Pause();
            image_an_layout.IsVisible = false;
        }
예제 #24
0
        private async void UnbookClicked(object s, EventArgs a)
        {
            if (loading)
            {
                return;
            }
            if (await App.SendSure())
            {
                loading = true;
                await DBActions.Unbook(binary.OWNER, binary.PRODUCT, true);

                MapPage.mapPage.ReloadAll();
                loading = false;
            }
        }
예제 #25
0
        private async void ButtonUnRetrieved(object s, EventArgs args)
        {
            if (loading)
            {
                return;
            }
            if (await DBActions.Check(MapPage._g as Admins, MapPage.mapPage))
            {
                return;
            }
            loading = true;
            await DBActions.Unbook(binary.OWNER, binary.PRODUCT, true);

            MapPage.mapPage.ReloadAll();
            loading = false;
        }
        protected override void EditItem()
        {
            System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(
                "Вы уверены, что хотите внести изменения?",
                "Предупреждение",
                System.Windows.MessageBoxButton.YesNo,
                System.Windows.MessageBoxImage.Warning
                );
            if (messageBoxResult == System.Windows.MessageBoxResult.No)
            {
                return;
            }

            DBActions.Update <Provider>(TempItem);
            ListCurrentData[ListCurrentData.IndexOf(SelectedDataItem)] = TempItem;
        }
예제 #27
0
        public void rel_admin(string f)
        {
            la_2.cardType = "user";
            vis_admin.Clear();
            List <Products> list = DBActions._a((Admins)MapPage._g);

            if (f != null && f != "")
            {
                f = f.ToLower();
                foreach (Guests g in DBActions.guests)
                {
                    if (g.Name.ToLower().StartsWith(f))
                    {
                        var l1 = DBActions.GetProducts(g);
                        foreach (Products p in l1)
                        {
                            if (list.Contains(p))
                            {
                                vis_admin.Add(new Binary {
                                    OWNER    = g, PRODUCT = p,
                                    QUANTITY = DBActions.GetQuantity(g, p)
                                });
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Guests g in DBActions.guests)
                {
                    var l1 = DBActions.GetProducts(g);
                    foreach (Products p in l1)
                    {
                        if (list.Contains(p))
                        {
                            vis_admin.Add(new Binary {
                                OWNER    = g, PRODUCT = p,
                                QUANTITY = DBActions.GetQuantity(g, p)
                            });
                        }
                    }
                }
            }
            la_2.visible = vis_admin;
            la_2.OpenPage(1, FilterState.BOOKERS);
        }
예제 #28
0
        private async void ButtonReset(object s, EventArgs args)
        {
            if (clicked)
            {
                return;
            }
            clicked = true;
            if (admin != null)
            {
                admin.Login = false;
                await DBActions.FullyEditAdmin(admin);

                search.Text = null;
                App.Send("Info", "Kontot med ID: " + admin.ID + " har återställts!", "Ok", ManagePage.page);
                stack.IsVisible = false;
                clicked         = false;
            }
        }
        protected override void RemoveItem()
        {
            System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(
                "Вы уверены, что хотите удалить выбранный элемент?",
                "Предупреждение",
                System.Windows.MessageBoxButton.YesNo,
                System.Windows.MessageBoxImage.Warning
                );
            if (messageBoxResult == System.Windows.MessageBoxResult.No)
            {
                return;
            }

            DBActions.Delete <Provider>(SelectedDataItem);
            ListCurrentData.Remove(SelectedDataItem);
            OnPropertyChanged("ListCurrentData");
            SelectedDataItem = ListCurrentData[ListCurrentData.Count - 1];
        }
예제 #30
0
 public static string CurrentUser()
 {
     using (SqlConnection con = new SqlConnection(connString, credentials))
     {
         try
         {
             return(DBActions.CurrentUser(con));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             return(null);
         }
         finally
         {
             con.Close();
         }
     }
 }
예제 #31
0
        public string ObjectTypeName; //This is the name of the DB Table.

        #endregion Fields

        #region Constructors

        public RepositoryEventsArgs(object obj, string objectTypeName, DBActions action)
        {
            Obj = obj;
            ObjectTypeName = objectTypeName;
            DBActionType = action;
        }