public DialogResult ShowDialog(DepositReturnTemplate returnTpl, User user) { this.returnTpl = returnTpl; this.user = user; string doPrint; if (LoginForm.ConfigReader.TryGetValue("printer", out doPrint)) if (doPrint.ToLower() == "false") btnPrintReceipt.Enabled = true; else btnPrintReceipt.Enabled = false; txtSum.Text = string.Format("{0:0.00}", (returnTpl.Cart.AmountWithDeposit - returnTpl.Cart.Amount)); dgvCartTable.Rows.Clear(); foreach (ArticleCount ac in returnTpl.Cart.Container) { dgvCartTable.Rows.Add( ac.Article.Deposit.Name, ac.Count, (ac.Article.PriceWithDeposit - ac.Article.Price), (ac.Article.PriceWithDeposit - ac.Article.Price) * ac.Count ); } // disable button if printer is busy btnPrintReceipt.Enabled = printDevice.PrintStatus == PrintStatus.Stopped; this.ShowDialog(); return System.Windows.Forms.DialogResult.OK; }
public Purchase(int purchaseId, Cart cart, User user, DateTime date) { this.PurchaseID = purchaseId; this.articles = cart; this.User = user; this.Date = date; }
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; }; }
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; }
public Cancellation(int cancellationId, User user, Article article, int count, DateTime created) { this.cancellationId = cancellationId; this.user = user; this.article = article; this.count = count; this.created = created; this.sum = article.Price * count; }
/// <summary> /// MessageChecker queries database for messages for the given user. If read messages are available, MessageReceived event is fired. /// </summary> /// <param name="interval">Interval in seconds to query for new messages.</param> /// <param name="user">User to look for as recipient.</param> public MessageChecker(int interval, User user) { if (interval < 10 || interval > 3600) throw new Exception("Das Zeitintervall muss zwischen 1 und 3600 Sekunden liegen"); if (user == null) throw new ArgumentNullException("Es muss ein Benutzerkonto angegeben werden."); this.user = user; timer = new System.Windows.Forms.Timer(); timer.Interval = interval * 1000; timer.Enabled = true; timer.Tick += timer_Tick; }
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; }
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(); }
public static ObservableCollection<User> GetUsers() { ObservableCollection<User> users = new ObservableCollection<User>(); try { SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("SELECT UserID, Username, PIN, Password, LockID, IsAdministrator, IsEnabled, IsDeleted, Created FROM [User] WHERE IsDeleted = 0", connection); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { User tmp = new User(); tmp.UserID = Convert.ToInt32(reader["UserID"]); tmp.Username = reader["Username"].ToString(); tmp.Pin = reader["PIN"].ToString(); tmp.Password = reader["Password"].ToString(); tmp.LockID = reader["LockID"].ToString(); tmp.IsAdministrator = Convert.ToBoolean(reader["IsAdministrator"]); tmp.IsEnabled = reader["IsEnabled"].ToString() == "True" ? true : false; tmp.IsDeleted = reader["IsDeleted"].ToString() == "True" ? true : false; tmp.Created = Convert.ToDateTime(reader["Created"]); tmp.Earned = GetUserEarnings(tmp); users.Add(tmp); } connection.Close(); } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Fehler beim Abrufen der Benutzerprofile.\n\n"; errmsg += "DatabaseHandler.GetUsers(): " + ex.Message; throw new Exception(errmsg); } return users; }
public void PrintBons(string organization, Cart articles, User person) { if (profile == null) throw new Exception("Druck konnte nicht ausgeführt werden: Kein Profil angegeben."); ReceiptBuilder printedBy = new ReceiptBuilder(); printedBy.Alignment = PrintAlignment.Center; printedBy.Font = FontType.B; printedBy.FeedLines(1); printedBy.Append("Ausgestellt von " + person.Username); printedBy.Font = FontType.A; printedBy.Alignment = PrintAlignment.Right; try { StringBuilder builder = new StringBuilder(); ReadOnlyCollection<Article> ro = articles.ToSeperatedArticleCollection(); foreach (Article art in ro) { if (!art.DoPrint) continue; builder.Append("\x1B\x40"); builder.Append("\x1B\x61\x1"); builder.Append("\x1B\x21\x0"); builder.Append(organization); builder.Append("\x1B\x64\x1"); builder.Append("\x1B\x21\x29"); builder.Append(profile.Name + "\xA"); // max 21 Zeichen! builder.Append("\xa"); builder.Append("\x1B\x21\x38"); builder.Append("\x1B\x2D\x2"); builder.Append(art.Name + "\xA"); builder.Append("\x1B\x21\x0"); builder.Append(printedBy.ToString()); //builder.Append("\r\nAusgestellt von " + person.Username + "\r\n"); builder.Append("\x1B\x64\x2"); builder.Append("\x1B\x61\x2"); builder.Append(DateTime.Now.ToString("D") + "\xA"); builder.Append("\x1D\x56\x42\x0"); builder.Append("@@@@@"); } Thread t = new Thread(delegate() { PrintThread(builder.ToString()); }); t.Start(); } catch (Exception ex) { WriteLog("Fehler beim Drucken der Bons: " + ex.Message); throw new Exception("Drucker nicht erreichbar."); } }
public void PrintDepositReturnReceipt(string organization, Cart articles, User person) { if (profile == null) throw new Exception("Druck konnte nicht ausgeführt werden: Kein Profil angegeben."); ReceiptBuilder printedBy = new ReceiptBuilder(); printedBy.Alignment = PrintAlignment.Center; printedBy.Font = FontType.B; printedBy.FeedLines(1); printedBy.Append("Gebucht auf " + person.Username); printedBy.Font = FontType.A; printedBy.Alignment = PrintAlignment.Right; printedBy.FeedLines(1); try { StringBuilder builder = new StringBuilder(); builder.Append("\x1B\x40"); builder.Append("\x1B\x61\x1"); builder.Append("\x1B\x21\x0"); builder.Append(organization); builder.Append("\x1B\x64\x1"); builder.Append("\x1B\x21\x29"); builder.Append(profile.Name + "\n\nPfandrückgabe\n\n"); // max 21 Zeichen! builder.Append("\n\xa"); //Beginn Artikel foreach (ArticleCount ac in articles.Container) { if (ac.Article.Deposit == Deposit.NullDeposit) continue; builder.Append("\x1B\x21\x1"); builder.Append("\x1B\x61\x0"); //linksbündig builder.Append(" " + ac.Count + "x " + string.Format("{0:0.00 EUR}", ac.Article.Deposit.Amount)); builder.Append("\x1B\x21\x0"); builder.Append(" " + ac.Article.Deposit.Name + "\xA"); builder.Append("\x1B\x61\x2"); //rechtsbündig builder.Append(string.Format("{0:0.00 EUR}", ac.Article.Deposit.Amount * ac.Count) + " "); builder.Append("\x1B\x64\x1"); //drucken + LF 2x } //ende Artikel builder.Append("\x1B\x64\x1"); //drucken + LF 1x builder.Append("------------------------------------------"); //Endsumme builder.Append("\x1B\x64\x1"); //drucken + LF 1x builder.Append("\x1B\x21\x29"); //Schriftgröße (Chr B, emph, d-width) builder.Append("SUMME " + string.Format("{0:0.00 EUR}", articles.AmountWithDeposit - articles.Amount)); //Ende Endsumme builder.Append("\x1B\x64\x2"); //drucken + LF 2x builder.Append(printedBy.ToString()); builder.Append("\x1B\x61\x2"); //rechtsbündig builder.Append("\x1B\x21\x1"); //Schriftgröße (klein) builder.Append(DateTime.Now.ToShortDateString()); builder.Append("\x1D\x56\x42"); builder.Append("\x1B\x64\x05"); // line feed builder.Append("\x1D\x56\x1"); // partial cut Thread t = new Thread(delegate() { PrintThread(builder.ToString()); }); t.Start(); } catch (Exception ex) { WriteLog(ex.ToString()); throw new Exception("Drucker nicht erreichbar."); } }
private void LoginWithPin(out User userref) { User usr = null; try { usr = (from u in this.users where u.Pin == txtPin.Text select u as User).First(); } catch (InvalidOperationException) { throw new Exception("Der PIN ist ungültig"); } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); throw new Exception("Programmfehler"); } if (usr.IsDeleted) throw new Exception("Der PIN ist ungültig"); if (!usr.IsEnabled) throw new Exception("Benutzer ist deaktiviert"); txtPin.Text = ""; lblPinMessage.Text = "Melden Sie sich an"; userref = usr; }
public PurchaseTemplate(Cart articles, User user) { this.Articles = articles; this.User = user; }
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; }
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; }
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; }
public CancellationTemplate(User user, Article article, int count) { this.User = user; this.Article = article; this.Count = count; }
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; }
public DepositReturnTemplate(Cart cart, User user, Profile profile) { this.cart = cart; this.user = user; this.profile = profile; }
public static User GetUser(int userID) { User user = null; try { SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("SELECT UserID, Username, PIN, [Password], LockID, IsAdministrator, IsEnabled, IsDeleted, Created FROM [User] WHERE UserID = " + userID, connection); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { user = new User(); user.UserID = Convert.ToInt32(reader["UserID"]); user.Username = reader["Username"].ToString(); user.Pin = reader["PIN"].ToString(); user.Password = reader["Password"].ToString(); user.LockID = reader["LockID"].ToString(); user.IsAdministrator = Convert.ToBoolean(reader["IsAdministrator"]); user.IsEnabled = reader["IsEnabled"].ToString() == "True" ? true : false; user.IsDeleted = reader["IsDeleted"].ToString() == "True" ? true : false; user.Created = Convert.ToDateTime(reader["Created"]); user.Earned = GetUserEarnings(user); } connection.Close(); if (user == null) throw new Exception("Der Benutzername ist nicht vergeben."); } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Fehler beim Abrufen des Benutzerprofils.\n\n"; errmsg += "DatabaseHandler.GetUser(userID): " + ex.Message; throw new Exception(errmsg); } return user; }
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; }
private static double GetUserEarnings(User user) { double earned = 0.0; string query = "SELECT SUM(a.Price*pa.ArticleCount) AS Amount FROM PurchasedArticle AS pa " + "INNER JOIN Purchase AS p ON pa.PurchaseID = p.PurchaseID " + "INNER JOIN Article AS a ON pa.ArticleID = a.ArticleID " + "WHERE p.UserID = " + user.UserID; try { SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader["Amount"] != DBNull.Value) earned = Convert.ToDouble(reader["Amount"]); } connection.Close(); } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Fehler beim Abrufen des Umsatzes des Benutzers.\n\n"; errmsg += "DatabaseHandler.GetUserEarnings(user): " + ex.Message; throw new Exception(errmsg); } return earned; }
public static void NewUserSession(User user) { if (user.CurrentSession == null) throw new Exception("Der Benutzer befindet sich momentan in keiner Sitzung."); try { string query = "SET DATEFORMAT dmy;" + "INSERT INTO [SESSION] (UserID, LoginTime, LastReply, Site) VALUES (" + user.UserID + "," + "'" + user.CurrentSession.LoginTime.ToString() + "'," + "'" + user.CurrentSession.LoginTime.ToString() + "'," + "'" + user.CurrentSession.Site + "')"; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Fehler beim Erstellen der Sitzung des Benutzers '" + user.Username + "'.\n\n"; errmsg += "DatabaseHandler.NewUserSession(user): " + ex.Message; throw new Exception(errmsg); } }
public static void SaveUser(User user) { try { string query = "UPDATE [User] SET "; query += "Username = '******',"; query += "PIN = '" + user.Pin + "',"; query += "Password = '******',"; query += "LockID = '" + user.LockID + "',"; query += "IsAdministrator = '" + user.IsAdministrator + "',"; query += "IsEnabled = '" + user.IsEnabled.ToString() + "',"; query += "IsDeleted = '" + user.IsDeleted.ToString() + "' "; query += "WHERE UserID = " + user.UserID; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (SqlException ex) { LogWriter.Write(ex, LOGFILE_NAME); foreach (SqlError err in ex.Errors) switch (err.Number) { case SqllErrorNumbers.DupKey: throw new Exception("Die eingegebenen Daten sind bereits vergeben."); } } catch (Exception ex) { LogWriter.Write(ex, LOGFILE_NAME); string errmsg = "Fehler beim Speichern des Benutzerprofils.\n\n"; errmsg += "DatabaseHandler.SaveUser(user): " + ex.Message; throw new Exception(errmsg); } }