コード例 #1
0
    protected void btnAddStu_onClick(object sender, EventArgs e)
    {
        string         stuId         = ddlSearch.SelectedValue.ToString();
        double         selectedStuId = Convert.ToDouble(stuId);
        int            lessID        = Convert.ToInt32(Session["selectedLessonNum"]);
        DateTime       lesDate       = Convert.ToDateTime(Session["selectedLessonDate"]);
        string         dateFormat    = lesDate.ToString("yyyy-MM-dd");
        ActualLesson   acl           = new ActualLesson();
        SignedToLesson stl;

        int studentsNum = Convert.ToInt32(Session["studentsNumber"]);
        int actual_quan = studentsNum + 1;

        try
        {
            stl = new SignedToLesson(lessID, dateFormat, selectedStuId);
            int numEffected3 = acl.updateSpecificActualLesson(lessID, dateFormat, actual_quan); //הגדלת כמות משתתפים ב-1
            int numEffected2 = stl.InsertSigendToLesson();                                      //הכנסת התלמיד לטבלת "רשום לתגבור"
            Server.TransferRequest(Request.Url.AbsolutePath, false);
        }
        catch (Exception ex)
        {
            Response.Write("There was an error " + ex.Message);
        }
    }
コード例 #2
0
ファイル: ShowRequests.aspx.cs プロジェクト: beja1990/Mevoot
    protected void ApproveButton_Click(object sender, EventArgs e)
    {
        Request     req         = new Request();
        GridViewRow gvRow       = (GridViewRow)(sender as Control).Parent.Parent;
        int         index       = gvRow.RowIndex;
        int         req_num     = Convert.ToInt32(gvRow.Cells[1].Text);
        int         status      = 1;
        int         numEffected = req.updateSpecificRequest(req_num, status);

        int    req_type     = 1;
        string req_typeName = gvRow.Cells[15].Text;

        if (req_typeName != "ביטול השתתפות")
        {
            req_type = 0;
        }


        ActualLesson   acl = new ActualLesson();
        SignedToLesson stl;
        double         stuId   = Convert.ToDouble(gvRow.Cells[3].Text);
        int            lesId   = Convert.ToInt32(gvRow.Cells[14].Text);
        DateTime       tmpDate = Convert.ToDateTime(gvRow.Cells[7].Text);
        string         lesDate = tmpDate.ToString("yyyy-MM-dd");


        if (req_type != 1) //אם זו בקשה להרשמה (זו לא בקשה לביטול השתתפות)
        {
            try
            {
                stl = new SignedToLesson(lesId, lesDate, stuId);
            }
            catch (Exception ex)
            {
                Response.Write("illegal values to the SignedToLesson attributes - error message is " + ex.Message);
                return;
            }

            int actual_quan = Convert.ToInt32(gvRow.Cells[11].Text) + 1;



            try
            {
                int numEffected3 = acl.updateSpecificActualLesson(lesId, lesDate, actual_quan); //הגדלת כמות משתתפים ב-1
                int numEffected2 = stl.InsertSigendToLesson();                                  //הכנסת התלמיד לטבלת "רשום לתגבור"
                Server.TransferRequest(Request.Url.AbsolutePath, false);
            }
            catch (Exception ex)
            {
                Response.Write("There was an error " + ex.Message);
            }
        }
    }
    protected void ApproveButton_Click(object sender, EventArgs e)
    {
        Session["flgSendReq"] = "1";
        Request     req     = new Request();
        GridViewRow gvRow   = (GridViewRow)(sender as Control).Parent.Parent;
        int         req_num = Convert.ToInt32(gvRow.Cells[1].Text);

        ActualLesson   acl = new ActualLesson();
        SignedToLesson stl;
        double         stuId   = Convert.ToDouble(gvRow.Cells[3].Text);
        int            lesId   = Convert.ToInt32(gvRow.Cells[5].Text);
        DateTime       tmpDate = Convert.ToDateTime(gvRow.Cells[7].Text);
        string         lesDate = tmpDate.ToString("yyyy-MM-dd");

        int    req_type     = 1;
        string req_typeName = gvRow.Cells[2].Text;

        if (req_typeName != "ביטול השתתפות")
        {
            req_type = 0;
        }
        else //נאשר בקשה לביטול השתתפות- נשנה סטטוס בקשה ל-1
        {
            int status      = 1;
            int numEffected = req.updateSpecificRequest(req_num, status);

            try
            {
                stl = new SignedToLesson(lesId, lesDate, stuId);
            }
            catch (Exception ex)
            {
                Response.Write("illegal values to the SignedToLesson attributes - error message is " + ex.Message);
                return;
            }

            int actual_quan = Convert.ToInt32(gvRow.Cells[13].Text) - 1;

            try
            {
                int numEffected3 = acl.updateSpecificActualLesson(lesId, lesDate, actual_quan); //הקטנת כמות משתתפים ב-1
                int numEffected2 = stl.deleteStudentFromLesson(stuId, lesId, lesDate);          //הוצאת התלמיד מטבלת "רשום לתגבור"
                Server.TransferRequest(Request.Url.AbsolutePath, false);
            }
            catch (Exception ex)
            {
                Response.Write("There was an error " + ex.Message);
            }
        }

        int       flg        = 0; //מסמן שאין התנגשות בין תגבור מבוקש לבין תגבור אחר כלשהו שהתלמיד משובץ אליו
        DataTable checkTable = new DataTable();

        checkTable.Columns.Add("flg", typeof(int)); //מסמן אם ניתן להוסיף תגבור או לא- 1 ניתן 0 לא ניתן

        if (req_type != 1)                          //אם זו בקשה להרשמה (זו לא בקשה לביטול השתתפות)
        {
            //ניקח את שעות התגבור המבוקש ע"מ לראות אם באותם שעות בתאריך התגבור, התלמיד משובץ לתגבור אחר
            DateTime reqLesStart = DateTime.Parse((gvRow.Cells[9].Text).ToString());
            DateTime reqLesEnd   = DateTime.Parse((gvRow.Cells[10].Text).ToString());

            Session["reqStuId"]   = stuId;
            Session["reqLesDate"] = lesDate;

            //נביא את כל התגבורים (תאריך+שעת התחלה+שעת סיום+מס תגבור) עבור מתגבר זה
            DataTable DTclassForReqStuId = this.GetClassForReqStuId();
            if (DTclassForReqStuId.Rows.Count > 0)//המשמעות שהתלמיד המבקש משובץ לתגבורים אחרים בתאריך המבוקש- נבדוק התנגשות בשעות
            {
                foreach (DataRow dr in DTclassForReqStuId.Rows)
                {
                    //אם יש לו תגבור באותו יום, אבל התגבור הנבחר מתחיל ומסתיים לפני התגבורים אחרים שיש לו באותו יום- ניתן לשבץ
                    if (reqLesStart < DateTime.Parse((dr["Les_StartHour"]).ToString()) && reqLesEnd <= DateTime.Parse((dr["Les_StartHour"]).ToString()))
                    {
                        DataRow newRow = checkTable.NewRow();
                        // Set values in the columnn:
                        newRow["flg"] = 1;
                        // Add the row to the rows collection.
                        checkTable.Rows.Add(newRow);
                    }
                    //אם יש לו תגבור באותו יום, אבל התגבור הנבחר מתחיל אחרי שהתגבורים אחרים שיש לו באותו יום כבר התחילו והסתיימו- ניתן לשבץ
                    else if (reqLesStart > DateTime.Parse((dr["Les_StartHour"]).ToString()) && reqLesStart >= DateTime.Parse((dr["Les_EndHour"]).ToString()))
                    {
                        DataRow newRow = checkTable.NewRow();
                        // Set values in the column
                        newRow["flg"] = 1;
                        // Add the row to the rows collection.
                        checkTable.Rows.Add(newRow);
                    }
                    else //כל מצב אחר המשמעות שיש תגבור לתלמיד באותו התאריך וגם השעות מתנגשות
                    {
                        DataRow newRow = checkTable.NewRow();
                        // Set values in the column
                        newRow["flg"] = 0;
                        // Add the row to the rows collection.
                        checkTable.Rows.Add(newRow);
                    }
                }
            }

            if (checkTable.Rows.Count > 0)
            {
                foreach (DataRow dr in checkTable.Rows)
                {
                    if (Convert.ToInt32(dr["flg"]) != 1)
                    {
                        flg = 1;
                        break;//מספיק שלפחות אחד מהתגבורים בתאריך זה מתנגש עם שעות התגבור הנבחר
                    }
                }
            }

            if (flg == 0)                                                                            //אין התנגשות, אז נבדוק האם יש מקום בתגבור ואם כן נאשר
            {
                if (Convert.ToInt32(gvRow.Cells[13].Text) < (Convert.ToInt32(gvRow.Cells[12].Text))) //אם יש מקום בתגבור הבקשה תאושר והתלמיד נרשם לתגבור
                {
                    int status      = 1;
                    int numEffected = req.updateSpecificRequest(req_num, status);

                    try
                    {
                        stl = new SignedToLesson(lesId, lesDate, stuId);
                    }
                    catch (Exception ex)
                    {
                        Response.Write("illegal values to the SignedToLesson attributes - error message is " + ex.Message);
                        return;
                    }

                    int actual_quan = Convert.ToInt32(gvRow.Cells[13].Text) + 1;



                    try
                    {
                        int numEffected3 = acl.updateSpecificActualLesson(lesId, lesDate, actual_quan); //הגדלת כמות משתתפים ב-1
                        int numEffected2 = stl.InsertSigendToLesson();                                  //הכנסת התלמיד לטבלת "רשום לתגבור"
                        Server.TransferRequest(Request.Url.AbsolutePath, false);
                    }
                    catch (Exception ex)
                    {
                        Response.Write("There was an error " + ex.Message);
                    }
                }
            }
            else //התלמיד משובץ כבר לתגבור אחר שמתנגש עם התגבור המבוקש- נדחה את הבקשה עם סיבת דחייה לתלמיד ואלרט למנהלת
            {
                int status       = 0;
                int Decliend     = 1;
                int numEffected  = req.updateSpecificRequest(req_num, status);    //נעדכן שהבקשה נדחתה
                int numEffected4 = req.updateReqDecliendField(req_num, Decliend); //נעדכן שהסיבה לדחיית הבקשה היא "אילוץ" ההתנגשות


                string   proffTitle    = gvRow.Cells[6].Text;
                string   start         = gvRow.Cells[9].Text;
                string   LesDateFormat = tmpDate.ToString("dd/MM/yyyy");
                string   currnetDate   = DateTime.Now.ToString("yyyy-MM-dd");
                Messages mes;
                Manager  m     = (Manager)(Session["manUserSession"]);
                double   manID = m.Man_id;


                string mesContent = "תלמיד יקר, שיעור " + proffTitle + " שחל בתאריך " + LesDateFormat + ", בשעה " + reqLesStart.ToString("HH:mm") + " מתנגש עם תגבור אחר שאתה משובץ אליו בתאריך זה";
                mes = new Messages(manID, stuId, "בקשתך להירשם לתגבור נדחתה", mesContent, false, currnetDate);
                int NumEffected = mes.InsertMessage();


                Session["declineReq"] = true;
                Server.TransferRequest(Request.Url.AbsolutePath, false);
            }
        }
    }