예제 #1
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            DBConnect db       = new DBConnect();
            appInfo   userInfo = new appInfo();
            bool      dbReturn = false;

            userInfo = getUserData();

            DialogResult diaResult = MessageBox.Show($"You are about to sumbit this info:\n" +
                                                     $"Start Time: " + userInfo.startTime + "\n" +
                                                     $"End Time: " + userInfo.endTime + "\n" +
                                                     $"Subject: " + userInfo.subject + "\n" +
                                                     $"Date: " + userInfo.appDate + "",
                                                     "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (diaResult == DialogResult.Yes)
            {
                dbReturn = db.insertApp(userInfo);
            }

            if (dbReturn == true)
            {
                MessageBox.Show($"Data inserted into database.", "Successful", MessageBoxButtons.OK);
                frontPageVisible(true);
                tutorWindowVisible(false);
            }
            else
            {
                MessageBox.Show($"Failed to insert data into database. Please contact admin!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                frontPageVisible(true);
                tutorWindowVisible(false);
            }

            resetOptions();
        }
예제 #2
0
        private appInfo getUserData()
        {
            appInfo user = new appInfo();

            user.userID = userIDBox.Text;

            if (appointmentCheck.Checked == true)
            {
                if (tuteeIDBox.Text == null)
                {
                    user.tuteeID = "0000000";
                }
                else if (tuteeIDBox.Text == "")
                {
                    user.tuteeID = "0000000";
                }
                else
                {
                    user.tuteeID = tuteeIDBox.Text;
                }
                //user.tuteeID = (tuteeIDBox.Text == (null) || "") ? "0000000" : tuteeIDBox.Text;
                DateTime startTime = new DateTime();
                startTime      = Convert.ToDateTime(startTimeBox.Text);
                user.startTime = startTime.ToString("HH:mm:ss");

                //Figure out endtime for an appointment
                if (twoHRApp.Checked == true)
                {
                    DateTime endtime = new DateTime();

                    endtime = Convert.ToDateTime(startTimeBox.Text);
                    endtime = endtime.AddHours(2);

                    user.endTime = endtime.ToString("HH:mm:ss");
                }
                else
                {
                    DateTime endtime = new DateTime();
                    endtime = Convert.ToDateTime(startTimeBox.Text);
                    endtime = endtime.AddHours(1);

                    user.endTime = endtime.ToString("HH:mm:ss");
                }

                StringBuilder sb = new StringBuilder();
                if (specProgCheckBox.Items.Count >= 1)
                {
                    for (int i = 0; i < specProgCheckBox.CheckedItems.Count; i++)
                    {
                        if (i == specProgCheckBox.CheckedItems.Count - 1)
                        {
                            sb.Append(specProgCheckBox.CheckedItems[i]);
                        }
                        else
                        {
                            sb.Append(specProgCheckBox.CheckedItems[i] + ",");
                        }
                    }
                    user.specPro = sb.ToString();
                }
                else
                {
                    user.specPro = null;
                }

                if (noShow.Checked == true)
                {
                    if (user.specPro == null || user.specPro == "")
                    {
                        user.specPro = "NoShow";
                    }
                    else
                    {
                        user.specPro += ",NoSow";
                    }
                }

                user.appDate   = DateTime.Now.ToString("yyyy-MM-dd");
                user.isEmbeded = false;
                user.subject   = appSubjects.Text;
            }
            else if (expressCheck.Checked == true)
            {
                DateTime startTime = new DateTime();
                startTime      = Convert.ToDateTime(startTimeBox.Text);
                user.startTime = startTime.ToString("HH:mm:ss");

                DateTime endTime = new DateTime();
                endTime      = Convert.ToDateTime(endTimeBox.Text);
                user.endTime = endTime.ToString("HH:mm:ss");

                user.appDate   = DateTime.Now.ToString("yyyy-MM-dd");
                user.isEmbeded = false;
                user.subject   = expressSubjects.Text;
            }
            else if (embedCheck.Checked == true)
            {
                System.Text.StringBuilder startSB = new StringBuilder();
                System.Text.StringBuilder endSB   = new StringBuilder();

                startSB.Append(startHr.Text + ":" + startMin.Text + ":00");
                endSB.Append(endHr.Text + ":" + endMin.Text + ":00");

                if (embedRadStart[0].Checked == true)
                {
                    startSB.Append(" AM");
                }
                else
                {
                    startSB.Append(" PM");
                }

                if (embedRadEnd[0].Checked == true)
                {
                    endSB.Append(" AM");
                }
                else
                {
                    endSB.Append(" PM");
                }

                user.startTime = DateTime.ParseExact(startSB.ToString(), "HH:mm:ss tt", CultureInfo.InvariantCulture).ToString("HH:mm:ss");
                user.endTime   = DateTime.ParseExact(endSB.ToString(), "hh:mm:ss tt", CultureInfo.InvariantCulture).ToString("HH:mm:ss");
                user.appDate   = DateTime.Now.ToString("yyyy-MM-dd");
                user.isEmbeded = true;
                user.subject   = appSubjects.Text;
            }

            //user.subject = appSubjects.Text;

            return(user);
        }