Exemple #1
0
        private void LoadSales()
        {
            if (loadingSales) return;

            Thread t = new Thread(new ThreadStart(() =>
            {
                try
                {
                    this.loadingSales = true;
                    User usr = null;
                    Invoke(new Action(() =>
                    {
                        if (closed)
                        {
                            Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                            return;
                        }
                        usr = (lbSalesUsers.SelectedItem as User);
                        dgvSales.Rows.Clear();
                    }));

                    IList<Purchase> sales = DatabaseHandler.GetUserPurchases(profile, usr);

                    foreach (Purchase p in sales)
                    {
                        foreach (ArticleCount ac in p.Articles)
                        {
                            if (closed)
                            {
                                Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                                return;
                            }
                            Invoke(new Action(() =>
                                {
                                    dgvSales.Rows.Add(
                                       p.PurchaseID,
                                       p.Date.ToString("dd.MM.yy HH:mm:ss"),
                                       ac.Article.Name,
                                       ac.Count,
                                       ac.Article.Price,
                                       string.Format("{0:0.00}", ac.Article.Price * ac.Count)
                                   );
                                }));
                        }
                    }

                    this.loadingSales = false;
                    RequestLoadingClosure();
                }
                catch(Exception ex)
                {
                    LogWriter.Write(ex);
                    this.loadingSales = false;
                    RequestLoadingClosure();
                }
            }));
            t.Start();

            if (!dlgLoading.Visible)
            {
                dlgLoading = new LoadingSalesForm();
                dlgLoading.ShowDialog();
            }
        }
Exemple #2
0
        private void LoadCancs()
        {
            if (loadingCancs) return;

            Thread t = new Thread(new ThreadStart(() =>
            {
                try
                {
                    this.loadingCancs = true;
                    User usr = null;
                    Invoke(new Action(() =>
                    {
                        if (closed)
                        {
                            Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                            return;
                        }
                        usr = (lbCancUsers.SelectedItem as User);
                        dgvCancs.Rows.Clear();
                    }));

                    ObservableCollection<Cancellation> cancs = DatabaseHandler.GetUserCancellations(profile, usr);

                    foreach (Cancellation c in cancs)
                    {
                        if (closed)
                        {
                            Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                            return;
                        }
                        Invoke(new Action(() =>
                        {
                            dgvCancs.Rows.Add(
                               c.CancellationId,
                               c.Created.ToString("dd.MM.yy HH:mm:ss"),
                               c.Article.Name,
                               c.Count,
                               c.Article.Price,
                               string.Format("{0:0.00}", c.Article.Price * c.Count)
                           );
                        }));
                    }

                    this.loadingCancs = false;
                    RequestLoadingClosure();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex);
                    this.loadingCancs = false;
                    RequestLoadingClosure();
                }
            }));
            t.Start();

            if (!dlgLoading.Visible)
            {
                dlgLoading = new LoadingSalesForm();
                dlgLoading.ShowDialog();
            }
        }
Exemple #3
0
        private void LoadDepReturns()
        {
            if (loadingDepReturns) return;

            Thread t = new Thread(new ThreadStart(() =>
            {
                try
                {
                    this.loadingDepReturns = true;
                    User usr = null;
                    Invoke(new Action(() =>
                    {
                        if (closed)
                        {
                            Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                            return;
                        }
                        usr = (lbDepReturnUsers.SelectedItem as User);
                        dgvDepReturns.Rows.Clear();
                    }));

                    List<DepositReturn> depReturns = DatabaseHandler.GetUserDepositReturnsDetailed(usr, profile);

                    foreach (DepositReturn d in depReturns)
                    {
                        if (closed)
                        {
                            Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                            return;
                        }
                        Invoke(new Action(() =>
                        {
                            dgvDepReturns.Rows.Add(
                                d.ReturnID,
                                d.Created.ToString("dd.MM.yy HH:mm:ss"),
                                d.Deposit.Name,
                                d.Count,
                                d.Deposit.AmountString,
                                string.Format("{0:0.00}", d.Deposit.Amount * d.Count)
                           );
                        }));
                    }

                    this.loadingDepReturns = false;
                    RequestLoadingClosure();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex);
                    this.loadingDepReturns = false;
                    RequestLoadingClosure();
                }
            }));
            t.Start();

            if (!dlgLoading.Visible)
            {
                dlgLoading = new LoadingSalesForm();
                dlgLoading.ShowDialog();
            }
        }
Exemple #4
0
        private void LoadGeneral()
        {
            if (loadingGeneral) return;
            Thread t = new Thread(new ThreadStart(() =>
            {
                try
                {
                    User usr = null;
                    Invoke(new Action(() =>
                    {
                        if (closed)
                        {
                            Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                            return;
                        }
                        usr = (lbGeneralUsers.SelectedItem as User);
                        dgvGeneral.Rows.Clear();
                    }));
                    Dictionary<string, string> stats = new Dictionary<string, string>();

                    Cart sales = DatabaseHandler.GetUserPurchaseSummary(profile, usr);
                    Cart cancs = DatabaseHandler.GetUserCancellationSummary(profile, usr);
                    Dictionary<Deposit,int> depReturns =DatabaseHandler.GetUserDepositReturns(usr, profile);

                    double depReturnSum = 0.0;         
                    foreach (KeyValuePair<Deposit, int> d in depReturns)
                        depReturnSum += d.Key.Amount * d.Value;

                    stats.Add("Umsatz vor Abzug Storno", string.Format("{0:0.00}", sales.Amount));
                    stats.Add("Umsatz nach Abzug Storno", string.Format("{0:0.00}", sales.Amount - cancs.Amount));
                    stats.Add("Pfand eingenommen", string.Format("{0:0.00}", (sales.AmountWithDeposit - cancs.AmountWithDeposit) - (sales.Amount - cancs.Amount)));
                    stats.Add("Pfand zurückgegeben", string.Format("{0:0.00}", depReturnSum));
                    stats.Add("Pfand offen", string.Format("{0:0.00}", (sales.AmountWithDeposit - cancs.AmountWithDeposit) - (sales.Amount - cancs.Amount) - depReturnSum));
                    stats.Add("Verkaufte Artikel vor Abzug Storno", sales.Count.ToString());
                    stats.Add("Verkaufte Artikel nach Abzug Storno", (sales.Count - cancs.Count).ToString());
                    stats.Add("Stornierte Artikel", cancs.Count.ToString());
                    stats.Add("Stornierte Summe", string.Format("{0:0.00}", cancs.Amount));

                    this.Invoke(new Action(() =>
                    {
                        foreach (KeyValuePair<string, string> kp in stats)
                        {
                            if (closed)
                            {
                                Invoke(new Action(() => { if (dlgLoading.Visible) dlgLoading.Close(); }));
                                return;
                            }
                            dgvGeneral.Rows.Add(kp.Key, kp.Value);
                        }
                    }));

                    this.loadingSales = false;
                    RequestLoadingClosure();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex);
                    this.loadingSales = false;
                    RequestLoadingClosure();
                }
            }));
            t.Start();

            if (!dlgLoading.Visible)
            {
                dlgLoading = new LoadingSalesForm();
                dlgLoading.ShowDialog();
            }
        }