Beispiel #1
0
        private void btnUpdateS_Click(object sender, RoutedEventArgs e)
        {
            bool         canInsert  = true;
            DateTime     start_time = new DateTime();
            DateTime     end_time   = new DateTime();
            TodayAllData sched      = (TodayAllData)dGrid.SelectedItem;

            try
            {
                start_time = DateTime.Parse(txtStartTime.Text);
                end_time   = DateTime.Parse(txtEndTime.Text);
            }
            catch
            {
                canInsert = false;
                MessageBox.Show("Ju lutem shkruani daten ne formatin e duhur \n(Viti-Muaji-Dita Ora:Min:Sec p.sh 2017-06-20 08:00:00).");
            }

            string reason      = txtReason.Text;
            int    schedule_id = int.Parse(txtschedule_id.Text);
            string query       = "INSERT INTO substitution(start_time, end_time, reason, schedule_id) VALUES ('" + start_time.ToString("yyyy-MM-dd hh:mm:ss") + "', '" + end_time.ToString("yyyy-MM-dd hh:mm:ss") + "', '" + reason + "', '" + schedule_id + "')"; sched.start_Time = DateTime.Parse(txtStartTime.Text);
            string existsDB    = "SELECT * FROM `substitution` WHERE `schedule_id`='" + schedule_id + "'";

            canInsert = canInsert && end_time > start_time;

            if (canInsert && !(Methods.existsInDBS(existsDB)))
            {
                Methods.updateOrInsertIntoTable(query);
                sched.start_Time = DateTime.Parse(txtStartTime.Text);
                sched.end_Time   = DateTime.Parse(txtEndTime.Text);
            }
            else if (Methods.existsInDBS(existsDB))
            {
                MessageBox.Show("Kjo lende tashme eshte zevendesuar!");
            }
            else
            {
                MessageBox.Show("Nuk mund te zevendesohet kjo lende!");
            }
        }
Beispiel #2
0
        void StartSubject(object sender, RoutedEventArgs e)
        {
            Button       btnFillo  = (Button)sender;
            TodayAllData todayData = (TodayAllData)gridTodaySubs.SelectedItem;

            todayData.lecHasBeenHeld();
            bool lectureWasHeld = todayData.lecIsOver;

            //Color white = (Color)ColorConverter.ConvertFromString("Red");
            // 50,205,50 - limegreen
            Methods.selectFromDbs("SELECT * FROM scheduler");

            int    subject_ID = todayData.subject_ID; //(int)cmbGroups.SelectedValue;
            int    lush_ID    = todayData.lush_ID;    //(int)cmbLush.SelectedValue;
            int    group_ID   = todayData.group_ID;   //(int)cmbSubjects.SelectedValue;
            string subject    = todayData.subject;
            string group      = todayData.group;
            string lush       = todayData.lush;

            now = Methods.datetimeInMysql();
            DateTime maxLecDuration     = new DateTime();
            double   maxMinutesToEndSub = 30;

            maxLecDuration = todayData.end_Time.AddMinutes(maxMinutesToEndSub);
            bool canEndSub = false;

            if (todayData.subActive)
            {
                TimeSpan minToAdd = TimeSpan.FromMinutes(10);
                TimeSpan minOfSubThatHasBeenHeld;
                TimeSpan foreseenMinForSub;
                foreseenMinForSub       = todayData.end_Time.Subtract(todayData.start_Time);
                minOfSubThatHasBeenHeld = (now.Subtract(todayData.hasStartedAt)).Add(minToAdd);
                if (minOfSubThatHasBeenHeld.TotalMinutes >= foreseenMinForSub.TotalMinutes)
                {
                    canEndSub = true;
                }
                else
                {
                    MessageBox.Show("Me vjen keq nuk mund te mbyllni kete ore");
                }
            }

            if (!todayData.subActive && btnFillo.IsEnabled && !lectureWasHeld)
            {
                DateTime startTime = new DateTime();
                TimeSpan compareStartToNow;
                string   startTimeQuery = "SELECT sch.start_time FROM scheduler sch " +
                                          "WHERE sch.subject_id=" + subject_ID + " AND sch.user_id=" + user_ID +
                                          " AND sch.group_id=" + group_ID + " AND sch.lush_id=" + lush_ID + "";

                startTime = Methods.startTimeOfSub(startTimeQuery);

                compareStartToNow = now.Subtract(startTime);
                // mos harro me uncommentu pjesen kjo osht veq per testim true
                if (true)//compareStartToNow.TotalMinutes >= -15 && compareStartToNow.TotalMinutes <= 15)
                {
                    try
                    {
                        bool check = (subject_ID > 0) && (lush_ID > 0) && (group_ID > 0);
                        if (check)
                        {
                            string message = "Deshironi te filloni oren " + todayData.subject + "?";
                            if (MessageBox.Show(message, "Konfirmoni", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                            {
                                string getStudOnGroup = "SELECT st.num_id, st.name, st.surname FROM cslgs c INNER JOIN subjects sub ON sub.subject_id=c.subject_id " +
                                                        "INNER JOIN lush l ON l.lush_id=c.lush_id INNER JOIN groups g ON g.group_id=c.group_id " +
                                                        "INNER JOIN students st ON st.student_id=c.student_id WHERE c.subject_ID='" + subject_ID + "' " +
                                                        "AND c.lush_id='" + lush_ID + "' AND c.group_id='" + group_ID + "'";

                                StudentsWindow stW = new StudentsWindow(subject_ID, lush_ID, group_ID);
                                stW.Show();

                                //Methods.fillDGTextbox(gridStudents, getStudOnGroup);
                                //int studentsCount = (gri.Items.Count);
                                MessageBox.Show("Ora " + todayData.subject + " filloi me sukses!");
                                todayData.subActive = true;
                                string startoOren = "INSERT INTO lecturetime(start_time, end_time, automatic_ended, schedule_id) VALUES('" + now.ToString("yyyy-MM-dd hh:mm:ss") + "', '" + maxLecDuration.ToString("yyyy-MM-dd hh:mm:ss") + "', 1, " + todayData.schedule_ID + ")";
                                Methods.updateOrInsertIntoTable(startoOren);
                                todayData.rowColor     = gold;
                                todayData.hasStartedAt = now;
                                todayData.btnContent   = "Perfundo";
                            }
                        }
                    }
                    catch { }
                }
                else if (compareStartToNow.TotalMinutes < -15)
                {
                    MessageBox.Show("Me vjen keq!\n Eshte heret per ta filluar oren");
                }
                else
                {
                    MessageBox.Show("Jeni Vonuar! Ju lutemi kerkoni leje nga dekani per te filluar kete ore.");
                }
            }
            else if (todayData.subActive && btnFillo.IsEnabled && canEndSub)
            {
                string message = "Deshironi te mbaroni oren " + todayData.subject + "?";
                if (MessageBox.Show(message, "Konfirmoni", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    string endTime = Methods.datetimeInMysql().ToString("yyyy-MM-dd hh:mm:ss");
                    ///////////////////////////  UPDATE FUNKSIONI QE THIRRET PREJ Methods.cs \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                    // Qeshtu e shkruni stringin edhe e thrrni funksionin me qat string variablat endTime edhe sch.schedule_ID  \\
                    // jon tdeklarume ma nalt.                                                                                    \\
                    /////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                    string mbaroOren = "UPDATE lecturetime SET end_time='" + endTime + "', automatic_ended='0' WHERE schedule_id=" + todayData.schedule_ID;
                    Methods.updateOrInsertIntoTable(mbaroOren);
                    todayData.subActive = false;
                    todayData.lecIsOver = true;
                    MessageBox.Show("Ora " + todayData.subject + " mbaroi me sukses!");
                    todayData.isEnabled  = false;
                    todayData.btnContent = "E perfunduar";
                    todayData.rowColor   = green;
                    todayData.hasEndedAt = now;
                }
            }
            else if (lectureWasHeld) //&& (todayData.hasEndedAt.ToShortDateString() != "1/1/0001"))
            {
                todayData.lecIsOver = true;
                todayData.isEnabled = false;
                MessageBox.Show("Ora " + todayData.subject + " eshte mbajtur");
                todayData.btnContent = "E perfunduar";
                todayData.rowColor   = green;
            }
        }