Esempio n. 1
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            string   timestamp     = SqlUpdater.CreateTimestamp();
            int      userId        = SqlUpdater.GetCurrentUserID();
            string   username      = SqlUpdater.GetCurrentUserName();
            int      appointmentId = Convert.ToInt32(SearchBar.Text);
            int      customerId    = Convert.ToInt32(TeamIdBox.Text);
            string   type          = TypeBox.Text;
            DateTime startTime     = DateTime.Parse(StartTimeBox.Text).ToUniversalTime();
            DateTime endTime       = DateTime.Parse(EndTimeBox.Text).ToUniversalTime();
            //String st = DateTime.Parse(StartTimeBox.Text).ToUniversalTime().ToString("u");
            //String et = DateTime.Parse(EndTimeBox.Text).ToUniversalTime().ToString("u");
            String st = DateTime.Parse(StartTimeBox.Text).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss");
            String et = DateTime.Parse(EndTimeBox.Text).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss");

            bool pass = Validator();

            if (pass)
            {
                try
                {
                    if (AppHasConflict(startTime, endTime))
                    {
                        throw new ScheduleException();
                    }
                    else
                    {
                        try
                        {
                            if (OutsideBusinessHours(startTime, endTime))
                            {
                                throw new ScheduleException();
                            }
                            else
                            {
                                SqlUpdater.UpdateAppt(customerId, userId, st, et, type, timestamp, username, appointmentId);

                                mainScheduleObject.UpdateCalendar();
                                MessageBox.Show("Update Sucessfull.");
                                Close();
                            }
                        }
                        catch (ScheduleException ex) { ex.BusinessHours(); }
                    }
                }
                catch (ScheduleException ex) { ex.AppOverlap(); }
            }

            else
            {
                MessageBox.Show("Add Schedule Error.");
            }
        }
        private void AddButton_Click(object sender, EventArgs e)
        {
            string   timestamp   = SqlUpdater.CreateTimestamp();
            int      userId      = SqlUpdater.GetCurrentUserID();
            string   userName    = SqlUpdater.GetCurrentUserName();
            DateTime startTime   = DateTime.Parse(StartTimeBox.Text).ToUniversalTime();
            DateTime endTime     = DateTime.Parse(EndTimeBox.Text).ToUniversalTime();
            string   type        = TypeBox.Text;
            int      teamId      = Convert.ToInt32(TeamIdBox.Text);
            string   st          = DateTime.Parse(StartTimeBox.Text).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss");
            string   et          = DateTime.Parse(EndTimeBox.Text).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss");
            string   title       = " ";
            string   description = " ";
            string   location    = " ";
            string   url         = " ";
            string   contact     = " ";

            bool pass = Validator();

            if (pass)
            {
                try
                {
                    if (AppHasConflict(startTime, endTime))
                    {
                        throw new ScheduleException();
                    }
                    else
                    {
                        try
                        {
                            if (OutsideBusinessHours(startTime, endTime))
                            {
                                throw new ScheduleException();
                            }
                            else
                            {
                                SqlUpdater.CreateSchedule("appointment", teamId, st, et, type, title, description, location, url, contact, timestamp, userName, userId);
                                mainScheduleObject.UpdateCalendar();


                                Close();
                            }
                        }
                        catch (ScheduleException ex) { ex.BusinessHours(); }
                    }
                }
                catch (ScheduleException ex) { ex.AppOverlap(); }
            }
Esempio n. 3
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);
        }