예제 #1
0
    public string insertALfromCal(string id, string date, string quantity)
    {
        int      numEffected   = 0;
        string   dt            = date;
        int      les_id        = Convert.ToInt16(id);
        int      Limitquantity = 0;
        DateTime start_date    = Convert.ToDateTime(dt);

        String   MyString   = date;
        DateTime MyDateTime = new DateTime();

        MyDateTime = DateTime.ParseExact(MyString, "yyyy-MM-dd", null);
        int day = (int)MyDateTime.DayOfWeek + 1;

        int          amount = Convert.ToInt32(quantity);
        ActualLesson al;

        for (int i = 0; i < amount; i++)
        {
            al           = new ActualLesson(les_id, dt, Limitquantity, day);
            numEffected += al.insertActualLesson();
            start_date   = start_date.AddDays(7);
            dt           = start_date.ToString("yyyy-MM-dd");
        }
        if (numEffected < 1)
        {
            return(null);
        }
        JavaScriptSerializer js = new JavaScriptSerializer();
        // serialize to string
        string jsonStringGetTurtering = js.Serialize(numEffected);

        return(jsonStringGetTurtering);
    }
예제 #2
0
    protected void generateDate_Click(object sender, EventArgs e)
    {
        Session["AddActualLesson"] = true;

        string       dt         = Request.Form["DatePickername"];
        int          les_id     = (int)(Session["LES_ID"]);
        int          quantity   = 0;
        DateTime     start_date = Convert.ToDateTime(dt);
        int          amount     = Convert.ToInt32(counterTB.Text);
        ActualLesson al;

        for (int i = 0; i < amount; i++)
        {
            al = new ActualLesson(les_id, dt, quantity);
            al.insertActualLesson();
            start_date = start_date.AddDays(7);
            dt         = start_date.ToString("yyyy-MM-dd");
        }
        string lessonCounter = counterTB.Text;

        Session["LessonCounterSession"] = lessonCounter;
        Response.Redirect("ShowActualLesson_admin.aspx");
    }
예제 #3
0
    protected void generateDate_Click(object sender, EventArgs e)
    {
        Session["AddActualLesson"] = true;
        string   dt         = Request.Form["DatePickername"];
        int      les_id     = (int)(Session["LES_ID"]);
        int      quantity   = 0;
        DateTime start_date = Convert.ToDateTime(dt);
        int      amount     = Convert.ToInt32(counterTB.Text);
        int      day        = Convert.ToInt32(dayOfActLesson.Text);

        // נבדוק מי מלמד את התגבור הנבחר ואת השעות של תגבור זה
        DataTable dtTeaID = this.GetSelectedTeaId();
        double    teaID   = Convert.ToDouble(dtTeaID.Rows[0]["Les_Tea_Id"]);
        DateTime  start   = DateTime.Parse((dtTeaID.Rows[0]["Les_StartHour"]).ToString());
        DateTime  end     = DateTime.Parse((dtTeaID.Rows[0]["Les_EndHour"]).ToString());

        Session["selectedteaID"] = teaID;

        //נביא את כל התגבורים (תאריך+שעת התחלה+שעת סיום+מס תגבור) עבור מתגבר זה
        DataTable DTclassForSelectedTeaId = this.GetClassForSelectedTeaId();

        int flg = 0; //מסמן אם יש התנגשות בזמנים

        ActualLesson al;


        DataTable checkTable = new DataTable();

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

        List <string> problemDatesList = new List <string>();
        List <string> goodDatesList    = new List <string>();

        for (int i = 0; i < amount; i++)
        {
            foreach (DataRow dr in DTclassForSelectedTeaId.Rows)
            {
                if (Convert.ToDateTime(dt) == Convert.ToDateTime(dr["ActLes_date"]))
                {
                    DateTime a = DateTime.Parse((dr["Les_StartHour"]).ToString());
                    //אם יש לו תגבור באותו יום, אבל התגבור הנבחר מתחיל ומסתיים לפני התגבורים אחרים שיש לו באותו יום- ניתן לשבץ
                    if (start < DateTime.Parse((dr["Les_StartHour"]).ToString()) && end <= 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 (start > DateTime.Parse((dr["Les_StartHour"]).ToString()) && start >= 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 == 1)
                {
                    DateTime date = Convert.ToDateTime(dt);
                    string   d    = date.ToString("dd'/'MM'/'yyyy");
                    problemDatesList.Add(d);
                }

                else //אף אחד מהתגבורים שקיימים כבר לא מתנגשים עם התאריך הנבחר
                {
                    al = new ActualLesson(les_id, dt, quantity, day);
                    al.insertActualLesson();;
                    DateTime date2 = Convert.ToDateTime(dt);
                    string   good  = date2.ToString("dd'/'MM'/'yyyy");
                    goodDatesList.Add(good);
                }
            }

            else //אם אין שורות בטבלה המשמעות שאין למתגבר תגבורים אחרים באותו יום ולכן אין בעיית שיבוץ וניתן להוסיף את התגבור
            {
                al = new ActualLesson(les_id, dt, quantity, day);
                al.insertActualLesson();
            }

            start_date = start_date.AddDays(7);
            dt         = start_date.ToString("yyyy-MM-dd");

            checkTable.Clear();
            flg = 0;
        }

        string goodAlert = "";

        if (goodDatesList.Count >= 1)
        {
            if (goodDatesList.Count == 1)
            {
                goodAlert = "המופע שהתווסף לתגבור הנבחר חל בתאריך: " + goodDatesList[0] + ".";
            }
            else
            {
                goodAlert = "המופעים שהתווספו לתגבור הנבחר חלים בתאריכים הבאים: ";

                for (int j = 0; j < goodDatesList.Count; j++)
                {
                    if (j != (goodDatesList.Count - 1))
                    {
                        goodAlert += (goodDatesList[j] + ", ");
                    }
                    else
                    {
                        goodAlert += (goodDatesList[j] + ".");
                    }
                }
            }

            Session["goodAlert"] = goodAlert;
        }


        if (problemDatesList.Count >= 1)
        {
            string alert;
            if (problemDatesList.Count == 1)
            {
                alert = "לא ניתן להוסיף למערכת את תבנית התגבור שנבחרה בתאריך הבא: " + problemDatesList[0] + ". המתגבר משובץ לתגבור אחר בשעות התגבור שבחרת";
            }
            else
            {
                alert = "לא ניתן להוסיף את תבנית התגבור שנבחרה בתאריכים הבאים: ";

                for (int j = 0; j < problemDatesList.Count; j++)
                {
                    if (j != (problemDatesList.Count - 1))
                    {
                        alert += (problemDatesList[j] + ", ");
                    }
                    else
                    {
                        alert += (problemDatesList[j] + ".תהמתגבר משובץ כבר לתגבור אחר בתאריכים אלה בשעות התגבור שבחרת. ");
                    }
                }
            }
            if (Session["goodAlert"] != null)
            {
                alert += Convert.ToString(Session["goodAlert"]);
            }
            Session["alert"] = alert;
            //Response.Write(@"<script language='javascript'>alert('" + alert + "');</script>");
        }

        int    lessonCounter = goodDatesList.Count;
        string wantedCounter = counterTB.Text;

        Session["LessonCounterSession"] = goodDatesList.Count;
        Session["wantedCounter"]        = wantedCounter;
        Response.Redirect("ShowActualLesson_admin.aspx");
    }