Beispiel #1
0
 private void loginButton_Click(object sender, EventArgs e)
 {
     if (FindUser(username.Text, password.Text) != 0)
     {
         this.Hide();
         MainForm MainForm = new MainForm();
         MainForm.loginForm = this;
         Logger.writeUserLoginLog(SqlUpdater.getCurrentUserID());
         MainForm.Show();
     }
     else
     {
         MessageBox.Show(errorMessage);
         password.Text = "";
     }
 }
Beispiel #2
0
        static public int FindUser(string userName, string password)
        {
            MySqlConnection C = new MySqlConnection(SqlUpdater.conString);

            C.Open();
            MySqlCommand    cmd = new MySqlCommand($"SELECT userId FROM user WHERE userName = '******' AND password = '******'", C);
            MySqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.HasRows)
            {
                rdr.Read();
                SqlUpdater.setCurrentUserID(Convert.ToInt32(rdr[0]));
                SqlUpdater.setCurrentUserName(userName);
                rdr.Close();
                return(SqlUpdater.getCurrentUserID());
            }
            return(0);
        }
Beispiel #3
0
        private void addButton_Click(object sender, EventArgs e)
        {
            string   timestamp = SqlUpdater.createTimestamp();
            int      userId    = SqlUpdater.getCurrentUserID();
            string   username  = SqlUpdater.getCurrentUserName();
            DateTime startTime = startTimeBox.Value.ToUniversalTime();
            DateTime endTime   = endTimeBox.Value.ToUniversalTime();


            try
            {
                if (appHasConflict(startTime, endTime))
                {
                    throw new appointmentException();
                }
                else
                {
                    try
                    {
                        if (outsideBusinessHours(startTime, endTime))
                        {
                            throw new appointmentException();
                        }
                        else
                        {
                            SqlUpdater.createRecord(timestamp, username, "appointment", $"'{customerIdBox.Text}', '{startTimeBox.Value.ToUniversalTime().ToString("u")}', '{endTimeBox.Value.ToUniversalTime().ToString("u")}', '{typeBox.Text}'", userId);
                            mainFormObject.updateCalendar();


                            Close();
                        }
                    }
                    catch (appointmentException ex) { ex.businessHours(); }
                }
            }
            catch (appointmentException ex) { ex.appOverlap(); }
        }
Beispiel #4
0
        static public Array getCalendar(bool weekView)
        {
            MySqlConnection c = new MySqlConnection(SqlUpdater.conString);

            c.Open();
            string          query = $"SELECT customerId, type, start, end, appointmentId, userId FROM appointment WHERE userid = '{SqlUpdater.getCurrentUserID()}'";
            MySqlCommand    cmd   = new MySqlCommand(query, c);
            MySqlDataReader rdr   = cmd.ExecuteReader();

            Dictionary <int, Hashtable> appointments = SqlUpdater.getAppointments();//new Dictionary<int, Hashtable>();


            while (rdr.Read())
            {
                Hashtable appointment = new Hashtable();
                appointment.Add("customerId", rdr[0]);
                appointment.Add("type", rdr[1]);
                appointment.Add("start", rdr[2]);
                appointment.Add("end", rdr[3]);
                appointment.Add("userId", rdr[5]);

                appointment.Add(Convert.ToInt32(rdr[4]), appointment);
            }
            rdr.Close();

            foreach (var app in appointments.Values)
            {
                query = $"SELECT userName FROM user WHERE userId = '{app["userId"]}'";
                cmd   = new MySqlCommand(query, c);
                rdr   = cmd.ExecuteReader();
                rdr.Read();
                app.Add("userName", rdr[0]);
                rdr.Close();
            }

            foreach (var app in appointments.Values)
            {
                query = $"SELECT customerName FROM customer WHERE customerId = '{app["customerId"]}'";
                cmd   = new MySqlCommand(query, c);
                rdr   = cmd.ExecuteReader();
                rdr.Read();
                app.Add("customerName", rdr[0]);
                rdr.Close();
            }

            Dictionary <int, Hashtable> parsedAppointments = new Dictionary <int, Hashtable>();

            foreach (var app in appointments)
            {
                DateTime startTime = DateTime.Parse(app.Value["start"].ToString());
                DateTime endTime   = DateTime.Parse(app.Value["end"].ToString());
                DateTime today     = DateTime.UtcNow;

                if (weekView)
                {
                    DateTime sunday   = today.AddDays(-(int)today.DayOfWeek);
                    DateTime saturday = today.AddDays(-(int)today.DayOfWeek + (int)DayOfWeek.Saturday);

                    if (startTime >= sunday && endTime < saturday)
                    {
                        parsedAppointments.Add(app.Key, app.Value);
                    }
                }
                else
                {
                    DateTime firstDayOfMonth = new DateTime(today.Year, today.Month, 1);
                    DateTime lastDayOfMonth  = firstDayOfMonth.AddMonths(1).AddDays(-1);
                    if (startTime >= firstDayOfMonth && endTime < lastDayOfMonth)
                    {
                        parsedAppointments.Add(app.Key, app.Value);
                    }
                }
            }

            SqlUpdater.setAppointments(appointments);

            var appointmentArray = from row in parsedAppointments select new {
                ID        = row.Key,
                Type      = row.Value["type"],
                StartTime = SqlUpdater.convertToTimezone(row.Value["start"].ToString()),
                EndTime   = SqlUpdater.convertToTimezone(row.Value["end"].ToString()),
                Customer  = row.Value["customerName"]
            };

            c.Close();


            return(appointmentArray.ToArray());
        }