Example #1
0
        public AdministrationForm(ObservableCollection<Profile> profiles, ObservableCollection<User> userList, User loggedInUser, Printer printer)
        {
            InitializeComponent();

            this.Activated += (s, e) => { StatusUpdater.Instance.Update(loggedInUser.Username, CashpointAction.ACTION_ADMIN); };

            this.loggedInUser = loggedInUser;
            this.profiles = profiles;
            this.users = userList;
            this.printer = printer;
            this.primaryProfile = (from p in profiles where p.IsPrimary select p as Profile).FirstOrDefault();

            this.Load += (sender, args) => 
            {
                if (printer.PrintStatus == PrintStatus.Printing) btnPrintResult.Enabled = false;
                printer.PrintStatusChanged += printer_PrintStatusChanged;

                lblProfile.Text = primaryProfile.Name;
                lblVersion.Text = Kasse.Properties.Resources.Version;
                lblDbVersion.Text = DatabaseHandler.GetDbVersion();
                lblUsername.Text = loggedInUser.Username;
                if (loggedInUser.CurrentSession == null)
                    loggedInUser.Login();
                TimeSpan ts = DateTime.Now - loggedInUser.CurrentSession.LoginTime;
                lblSessionTime.Text = ts.ToString("hh") + ":" + ts.ToString("mm") + ":" + ts.ToString("ss");
                Timer t = new Timer() { Interval = 1000 };
                t.Tick += (s, a) => {
                    try
                    {
                        if (loggedInUser != null && loggedInUser.CurrentSession != null)
                        {
                            TimeSpan span = DateTime.Now - loggedInUser.CurrentSession.LoginTime;
                            lblSessionTime.Text = span.ToString("hh") + ":" + span.ToString("mm") + ":" + span.ToString("ss");
                        }
                        else
                            lblSessionTime.Text = "- Fehler -";
                    }
                    catch (Exception ex)
                    {
                        LogWriter.Write(ex, LOGFILE_NAME);
                    }
                    
                };
                t.Enabled = true;

                lblRefreshEnabled.Text = LoginForm.CashpointSettings["AutoRefresh"].ToLower() == "auto" ? "Automatisch" : "Manuell";
                lblRefreshInterval.Text = LoginForm.CashpointSettings["AutoRefreshInterval"];
                btnToggleAutorefresh.Text = LoginForm.CashpointSettings["AutoRefresh"].ToLower() == "auto" ? "Aktualisierung (Ein)" : "Aktualisierung (Aus)";
                ConfigurationReader configReader = new ConfigurationReader(ConfigurationReader.CONFIGURATION_FILE_NAME);
                lblHost.Text = configReader.GetValue("server");
                lblLiveview.Text = LoginForm.CashpointSettings["LiveViewEndpoint"] + " (" + (StatusUpdater.Instance.IsInitialized ? "online" : "offline") + ")";

                cmbUsers.DataSource = userList;
                cmbArticles.DataSource = primaryProfile.Articles;
                cmbResultProfile.DataSource = profiles;
                cmbResultUser.DataSource = userList;
            };
        }
Example #2
0
 public DepositReturn(int returnID, Deposit deposit, Profile profile, User user, int count, DateTime created)
 {
     this.returnID = returnID;
     this.deposit = deposit;
     this.profile = profile;
     this.user = user;
     this.count = count;
     this.created = created;
 }
Example #3
0
        public CreatingResultForm(Profile profile, User user)
        {
            InitializeComponent();

            this.duration=new TimeSpan();
            this.timer = new System.Windows.Forms.Timer();
            timer.Interval = 1000;
            timer.Tick += (s, e) =>
            {
                duration = duration.Add(new TimeSpan(0, 0, 1));
                lblTime.Text = duration.ToString("mm") + ":" + duration.ToString("ss");
            };
            timer.Enabled = true;
            timer.Start();

            this.user = user;
            this.profile = profile;
        }
Example #4
0
        public JournalForm(Profile profile, User user)
        {
            InitializeComponent();


            this.Activated += (s, e) => 
            {
                StatusUpdater.Instance.Update(StatusUpdater.Instance.LastUser, CashpointAction.ACTION_JOURNAL); 
            };
            
            this.FormClosing += (s, e) => { closed = true; };

            this.profile = profile;
            this.user = user;
            this.closed = false;
            this.loadingSales = false;
            this.loadingGeneral = false;
            this.dlgLoading = new LoadingSalesForm();
        }
Example #5
0
        public DepositRegisterForm(ObservableCollection<Profile> profiles, ObservableCollection<User> users, Printer printDevice)
        {
            InitializeComponent();

            this.Activated += (s, e) => 
            {
                StatusUpdater.Instance.Update(userLoggedIn.Username, CashpointAction.ACTION_REGISTER);
                Invoke(new Action(() => { btnExit.Enabled = userLoggedIn.IsAdministrator; }));
            };

            // remove articles without deposit
            foreach (Profile p in profiles)
            {
                p.Articles =
                    new ObservableCollection<Article>(
                    (from a in p.Articles where a.Deposit != Deposit.NullDeposit select a).ToList()
                );
            }

            this.printDevice = printDevice;
            this.profiles = profiles;
            this.users = users;
            primaryProfile = (from p in profiles where p.IsPrimary == true select p as Profile).First();
            printDevice.Profile = primaryProfile;

            List<int> addedDeposits = new List<int>();
            foreach (Article a in primaryProfile.Articles)
            {
                if(!addedDeposits.Contains(a.Deposit.DepositID))
                {
                    DepositButton btn = a.Button.ToDepositButton();
                    btn.Cart = this.cart;
                    this.Controls.Add(btn);
                    addedDeposits.Add(a.Deposit.DepositID);
                }
            }

            this.cart.CartChanged += RefreshCartGUI;
            dgvCartTable.Font = new Font(dgvCartTable.Font.FontFamily, 11.0F, FontStyle.Regular);

            // add eventhandler for successed sales to trigger printer
            this.SaleSuccessed += RegisterForm_SaleSuccessed;

            // reset refresh pending
            this.Shown += (a, b) =>
            {
                this.RefreshNeeded = false;
            };

            // log user off when form hides
            this.FormClosing += (e, args) =>
            {
                try
                {
                    cart.Clear();
                    userLoggedIn.Logout();
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex, LOGFILE_NAME);
                    MessageBox.Show("Programmfehler: " + ex.ToString());
                }
            };

            // create dialogs
            confirmationDialog = new PurchaseSummaryForm(printDevice);

            // bottom labels
            lblProfile.Text = primaryProfile.Name;
            lblTime.Text = DateTime.Now.ToString("HH:mm:ss");
            time = new Timer();
            time.Interval = 1000;
            time.Tick += (sender, e) => { lblTime.Text = DateTime.Now.ToString("HH:mm:ss"); };

            // logout timer
            logoutHoldTimer = new Timer();
            int duration = Convert.ToInt32(LoginForm.CashpointSettings["HoldLogoutDuration"]);
            logoutHoldTimer.Interval = duration > 0 ? duration * 1000 : 1;
            logoutHoldTimer.Tick += delegate(object sender, EventArgs e)
            {
                logoutHoldTimer.Stop();
                if (cart.Count > 0 && loginMode == LoginForm.LoginMode.Key)
                {
                    if (discardForm.ShowDialog(userLoggedIn.Username) == DialogResult.OK)
                    {
                        cart.Clear();
                        if (refreshNeeded) this.Close();
                        this.Hide();
                    }
                }
                else
                    this.Hide();
            };
            btnLogout.MouseDown += delegate(object sender, MouseEventArgs mea)
            {
                logoutHoldTimer.Start();
            };
            btnLogout.MouseUp += delegate(object sender, MouseEventArgs mea)
            {
                logoutHoldTimer.Stop();
            };

            // printer status subscription
            printDevice.PrintStatusChanged += (sender, e) =>
            {
                try
                {
                    if (e.NewStatus == PrintStatus.Printing)
                        btnPrint.Invoke(new Action(() => btnPrint.Enabled = false));
                    else
                    {
                        if (cart.Count > 0)
                            btnPrint.Invoke(new Action(() => { btnPrint.Enabled = true; btnReset.Enabled = true; }));
                    }
                }
                catch (Exception ex)
                {
                    LogWriter.Write(ex, LOGFILE_NAME);
                    MessageBox.Show(ex.Message);
                }
            };

            // set picture boxes
            pctRefreshPending.Image = Resources.Get(Resources.Images.RefreshPending);
            pctPaperNearOut.Image = Resources.Get(Resources.Images.PrinterIconSmall);
            if (printDevice.DeviceStatusCode == 25) pctPaperNearOut.Visible = true;

            // create discard form
            discardForm = new DiscardCartForm();

            // create popups
            Popups = new Dictionary<Popup, Form>();
            Popups = new Dictionary<Popup, Form>();
            Popups.Add(Popup.RefreshInvoked, new InformRefreshInvokedForm());
            Popups.Add(Popup.RefreshNow, new InformRefreshPopupForm());
            Popups.Add(Popup.ShowMessage, new ShowMessageForm());

        }
Example #6
0
 public DepositReturnTemplate(Cart cart, User user, Profile profile)
 {
     this.cart = cart;
     this.user = user;
     this.profile = profile;
 }
Example #7
0
        public static Cart GetUserCancellationSummary(Profile profile, User user)
        {
            Cart c = new Cart();

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT [Artikel],[Anzahl] FROM [KASSE].[dbo].[vCancellationSummaryUserDetailed] WHERE Benutzer = '" + user.Username + "' AND Veranstaltung = '" + profile.Name + "' ORDER BY Summe DESC", connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ArticleCount ac = new ArticleCount(GetArticle(profile.ProfileID, reader["Artikel"].ToString()), Convert.ToInt32(reader["Anzahl"]));
                    c.Add(ac);
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                LogWriter.Write(ex, LOGFILE_NAME);
                string errmsg = "Fehler beim Abrufen der Benutzerstornos.\n\n";
                errmsg += "DatabaseHandler.GetUserCancellationSummary(profile, user): " + ex.Message;
                throw new Exception(errmsg);
            }

            return c;
        }
Example #8
0
        public static Profile GetProfile(string profilename)
        {
            Profile p = null;

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT * FROM Profile WHERE Name = '" + profilename + "'", connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    p = new Profile(
                        Convert.ToInt32(reader["ProfileID"]),
                        reader["Name"].ToString(),
                        Convert.ToBoolean(reader["IsPrimary"]),
                        Convert.ToBoolean(reader["IsDeleted"]),
                        Convert.ToDateTime(reader["Created"]),
                        GetArticles(Convert.ToInt32(reader["ProfileID"])),
                        GetDeposites()
                    );
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                LogWriter.Write(ex, LOGFILE_NAME);
                string errmsg = "Fehler beim Abrufen des Profils.\n\n";
                errmsg += "DatabaseHandler.GetProfile(profilename): " + ex.Message;
                throw new Exception(errmsg);
            }

            if (p == null)
                throw new Exception("Es existiert kein Profil mit der angegebenen ProfilID (" + profilename + ")\n\nDatabaseHandler.GetProfile(profilename)");

            return p;
        }
Example #9
0
        public static Profile GetPrimaryProfile()
        {
            Profile profile = null;

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT * FROM Profile WHERE IsPrimary = 1", connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    profile = new Profile(
                        Convert.ToInt32(reader["ProfileID"]),
                        reader["Name"].ToString(),
                        Convert.ToBoolean(reader["IsPrimary"]),
                        Convert.ToBoolean(reader["IsDeleted"]),
                        Convert.ToDateTime(reader["Created"]),
                        GetArticles(Convert.ToInt32(reader["ProfileID"])),
                        GetDeposites()
                    );
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                LogWriter.Write(ex, LOGFILE_NAME);
                string errmsg = "Fehler beim Abrufen der Profile.\n\n";
                errmsg += "DatabaseHandler.GetProfiles(): " + ex.Message;
                throw new Exception(errmsg);
            }

            return profile;
        }
Example #10
0
        public static ObservableCollection<Cancellation> GetUserCancellations(Profile profile, User user)
        {
            ObservableCollection<Cancellation> cancellations = new ObservableCollection<Cancellation>();

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(@"
                        SELECT 
	                        c.CancellationID,
	                        c.UserID,
	                        c.ArticleID,
	                        c.ArticleCount,
	                        c.Created
                        FROM Cancellation AS c
                        INNER JOIN Article AS a
                        ON c.ArticleID = a.ArticleID
                        WHERE ProfileID = " + profile.ProfileID + " AND UserID = " + user.UserID + @" 
                        ORDER BY c.Created DESC
                    ", connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    cancellations.Add(new Cancellation(
                            Convert.ToInt32(reader["CancellationID"]),
                            user,
                            GetArticle(Convert.ToInt32(reader["ArticleID"])),
                            Convert.ToInt32(reader["ArticleCount"]),
                            Convert.ToDateTime(reader["Created"])
                        ));
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                string errmsg = "Fehler beim Abrufen der Stornos.\n\n";
                errmsg += "DatabaseHandler.GetUserCancellations(profile, user): " + ex.ToString();
                throw new Exception(errmsg);
            }

            return cancellations;
        }
Example #11
0
        public static ObservableCollection<Purchase> GetUserPurchases(Profile profile, User user)
        {
            _loadPurchasesUserCache = new List<User>();
            _loadPurchasesArticleCache = new List<Article>();

            ObservableCollection<Purchase> purchases = new ObservableCollection<Purchase>();
            GetPurchaseArticleCache = new List<Article>();
            GetPurchaseUserCache = new List<User>();

            int currentPurchaseId = -1;
            Purchase p = null;
            Cart c = null;
            User u = null;
            Article a = null;

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT PurchaseID, UserID, ArticleID, ArticleCount, [Date] FROM vPurchaseProfile WHERE ProfileID = " + profile.ProfileID +
                    " AND UserID = " + user.UserID + " ORDER BY [Date] DESC", connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int pid = Convert.ToInt32(reader["PurchaseID"]);
                    int artId = Convert.ToInt32(reader["ArticleID"]);

                    // article cache
                    a = (from art in _loadPurchasesArticleCache where art.ArticleID == artId select art as Article).FirstOrDefault();
                    if (a == null) { a = GetArticle(artId); _loadPurchasesArticleCache.Add(a); }

                    if (currentPurchaseId == -1 || pid != currentPurchaseId)    // create new purchase object
                    {
                        int userId = Convert.ToInt32(reader["UserID"]);

                        if (p != null) purchases.Add(p);

                        // user cache
                        u = (from usr in _loadPurchasesUserCache where usr.UserID == userId select usr as User).FirstOrDefault();
                        if (u == null) { u = GetUser(userId); _loadPurchasesUserCache.Add(u); }

                        currentPurchaseId = pid;
                        c = new Cart();
                        p = new Purchase(pid, c, u, Convert.ToDateTime(reader["Date"]));
                        c.Add(a, Convert.ToInt32(reader["ArticleCount"]));
                    }
                    else    // add article to purchase object
                    {
                        c.Add(a, Convert.ToInt32(reader["ArticleCount"]));
                    }
                }
                if (!purchases.Contains(p) && p != null) purchases.Add(p);
                connection.Close();
            }
            catch (Exception ex)
            {
                string errmsg = "Fehler beim Abrufen der Verkäufe.\n\n";
                errmsg += "DatabaseHandler.GetUserPurchases(profile, user): " + ex.ToString();
                throw new Exception(errmsg);
            }

            return purchases;
        }
Example #12
0
        public static List<DepositReturn> GetUserDepositReturnsDetailed(User user, Profile profile)
        {
            List<DepositReturn> deps = new List<DepositReturn>();

            string command = @"
                SELECT *
                FROM DepositReturn
                WHERE userId = " + user.UserID + " AND ProfileID = " + profile.ProfileID;
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand(command, connection);
            connection.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Deposit d = GetDeposit(Convert.ToInt32(reader["DepositID"]));

                deps.Add(new DepositReturn(
                        Convert.ToInt32(reader["ReturnID"]),
                        d,
                        profile,
                        user,
                        Convert.ToInt32(reader["Count"]),
                        Convert.ToDateTime(reader["Created"])
                    ));
            }
            connection.Close();

            return deps;
        }
Example #13
0
        public static Dictionary<Deposit, int> GetUserDepositReturns(User user, Profile profile)
        {
            Dictionary<Deposit, int> res = new Dictionary<Deposit, int>();

            string command = @"
                SELECT DepositID, ProfileID, UserID, sum([count]) AS [Count] 
                FROM DepositReturn
                WHERE userId = " + user.UserID + " AND ProfileID = " + profile.ProfileID + @" 
                GROUP BY DepositID, ProfileID, UserID;
            ";
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand(command, connection);
            connection.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Deposit d = GetDeposit(Convert.ToInt32(reader["DepositID"]));
                User u = GetUser(Convert.ToInt32(reader["ProfileID"]));

                res[d] = Convert.ToInt32(reader["Count"]);
            }
            connection.Close();

            return res;
        }
Example #14
-2
        public Printer(string logicalName, bool connect)
        {
            instance = this;
            if (connect)
            {
                this.profile = null;
                this.deviceStatus = PrintDeviceStatus.Properly;
                this.PrintStatus = PrintStatus.Stopped;

                try
                {
                    DeviceInfo deviceInfo = null;
                    PosExplorer posExplorer = new PosExplorer();
                    deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, logicalName);
                    device = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
                    device.Open();
                    device.Claim(1000);
                    device.AsyncMode = false;
                    device.DeviceEnabled = true;

                    device.StatusUpdateEvent += Device_StatusUpdateEvent;
                    device.ErrorEvent += (a, b) => { WriteLog("ERROR - " + b.ToString()); };
                    WriteLog("");
                    WriteLog("Drucker initialisiert; Status: " + device.State + device);
                    if (device.RecNearEnd) Device_StatusUpdateEvent(this, new StatusUpdateEventArgs(25));
                    this.connected = connect;
                }
                catch (Exception ex)
                {
                    string s = ex.Source;
                    try
                    {
                        if (device != null)
                            device.Release();
                    }
                    catch { }
                    throw new Exception("Verbindung zum Drucker fehlgeschlagen.", ex);
                }
            }
            else
            {
                this.connected = false;
                this.PrintStatus = PrintStatus.Stopped;
                this.deviceStatus = PrintDeviceStatus.Properly;
            }
        }