public string getCalenderShifts() { List <ShiftsEmployee> shiftlist = new List <ShiftsEmployee>(); DBservices ds = new DBservices(); DataTable dt = ds.ReadFromDataBaseCalender("rikosheTDBConnectionString", "[ShiftAfterScheduling]"); foreach (DataRow row in dt.Rows) { string shiftsString = Convert.ToString(row["Content"]); string[] shifts = shiftsString.Split(','); string emp = Convert.ToString(row["FirstName"]); string start = Convert.ToString(row["StartTime"]); string startDate = start.Split(' ')[0]; string[] startArr = startDate.Split('/'); start = startArr[2] + "-" + startArr[1] + "-" + startArr[0]; string end = Convert.ToString(row["FinishTime"]); string endDate = end.Split(' ')[0]; string[] endArr = endDate.Split('/'); end = endArr[2] + "-" + endArr[1] + "-" + endArr[0]; foreach (string item in shifts) { ShiftsEmployee se = new ShiftsEmployee(); se.Title = emp; se.Start = start; se.End = end; se.Type = Convert.ToInt32(item); shiftlist.Add(se); } } string temp = writeToJson(shiftlist); return(temp); }
protected void LoadEmployees() { Employee emp = new Employee(); List <Employee> empL = emp.getEmployeeList(); ShiftsEmployee shiftEmp = new ShiftsEmployee(); List <ShiftsEmployee> shiftEmpList = shiftEmp.GetShiftsList(); foreach (Employee empTemp in empL) { HtmlGenericControl divEmpl = new HtmlGenericControl("div"); divEmpl.Attributes["class"] = "btn list"; divEmpl.ID = empTemp.First_name; divEmpl.Attributes["draggable"] = "true"; divEmpl.Attributes["ondragstart"] = "drag(event)"; string list = ""; foreach (ShiftsEmployee item in empTemp.Last_shift) { if (list == "") { list = Convert.ToString(item.Type); } else { list += "0" + Convert.ToString(item.Type); } } divEmpl.Attributes["onmouseover"] = "employeePerfernce(" + list + ")"; divEmpl.Attributes["onmouseout"] = "clearShiftTable()"; divEmpl.InnerHtml = empTemp.First_name + " " + empTemp.Last_name; divEmpl.InnerHtml += " <span class='badge badge-pill badge-danger tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span><span id='" + empTemp.User_name + "'>" + 0 + "<span></span>"; divEmpl.ID = Convert.ToString(empTemp.First_name + "_" + empTemp.Last_name + "_" + empTemp.User_name); EmployeeList.Controls.Add(divEmpl); } }
public string getCalenderShifts() { ShiftsEmployee SE = new ShiftsEmployee(); string p = SE.getCalenderShifts(); return(p); }
public string insertSwitch(int emp, int shift, string type) { ShiftsEmployee se = new ShiftsEmployee(); int S = se.insertSwitch(emp, shift, type); JavaScriptSerializer js = new JavaScriptSerializer(); string jsonString = js.Serialize(S); return(jsonString); }
public string approveSwitch(int empTake, int empAsk, int shift, string type) { ShiftsEmployee se = new ShiftsEmployee(); int S = se.approveSwitch(empTake, empAsk, shift, type); JavaScriptSerializer js = new JavaScriptSerializer(); string jsonString = js.Serialize(S); return(jsonString); }
public string insertShiftAfterEditing(string shift) { ShiftsEmployee sh = new ShiftsEmployee(); int numAffected = sh.insertShiftAfterEditing(shift); JavaScriptSerializer js = new JavaScriptSerializer(); string jsonString = js.Serialize(numAffected); return(jsonString); }
public string getChanges() { ShiftsEmployee empl = new ShiftsEmployee(); List <string> emplList = empl.getEmployeeSObjects(); JavaScriptSerializer js = new JavaScriptSerializer(); string jsonString = js.Serialize(emplList); return(jsonString); }
public string getSwitch(int id) { ShiftsEmployee se = new ShiftsEmployee(); string S = se.getSwitch(id); JavaScriptSerializer js = new JavaScriptSerializer(); string jsonString = js.Serialize(S); return(jsonString); }
public Employee loginUser(int userName, string Password) { Employee emp = new Employee(); SqlConnection con = null; try { con = connect("rikosheTDBConnectionString"); // create a connection to the database using the connection String defined in the web config file //String selectSTR = "select * from Employee E inner join [Employee Type] ET ON E.Type=ET.ID INNER JOIN [Shift Before Scheduling] SBS ON E.ID=SBS.EmployeeID"; String selectSTR = "SELECT * FROM [igroup80_test2].[dbo].[Employee] E INNER JOIN (SELECT [ID],[FirstTime],[FinishTime],[Content],[EmployeeID] FROM [igroup80_test2].[dbo].[Shift Before Scheduling]WHERE [ID] IN (SELECT [ID] FROM (SELECT [ID],RANK() OVER (PARTITION BY [EmployeeID] ORDER BY [ID] DESC) AS RankNO FROM [igroup80_test2].[dbo].[Shift Before Scheduling])AS T WHERE T.RankNO='1')) SBS ON E.ID=SBS.EmployeeID WHERE [UserName]=" + userName + " AND [Password]='" + Password + "'"; SqlCommand cmd = new SqlCommand(selectSTR, con); // get a reader SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end while (dr.Read()) { // Read till the end of the data into a row Employee Empl = new Employee(); Empl.First_name = Convert.ToString(dr["FirstName"]); Empl.Last_name = Convert.ToString(dr["LastName"]); Empl.User_name = Convert.ToInt32(dr["UserName"]); Empl.Password = Convert.ToString(dr["Password"]); Empl.Type = Convert.ToString(dr["Type"]); Empl.Branch = Convert.ToString(dr["Branch"]); Empl.Minimum = Convert.ToInt32(dr["Minimum"]); List <ShiftsEmployee> EmplL = new List <ShiftsEmployee>(); string temp = Convert.ToString(dr["Content"]); string[] tempString = temp.Split(','); foreach (string item in tempString) //כל העדפה של עובד תשמר באובייקט מיטחד של משמרת { ShiftsEmployee tempSE = new ShiftsEmployee(); tempSE.Title = Empl.First_name; tempSE.Type = Convert.ToInt32(item); EmplL.Add(tempSE); } Empl.Last_shift = EmplL; emp = Empl; } return(emp); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); } } }
protected void SaveShift(object sender, EventArgs e) { ShiftsEmployee tempEmp = new ShiftsEmployee(); try { string stringList = Request.Cookies["ListShiftAfterEditing"].Value; int numEffected = tempEmp.SaveShiftsAfterEditing(stringList); Response.Redirect("Shifts.aspx"); } catch (Exception ex) { Response.Write("There was an error when trying to insert the shift into the database" + ex.Message); } }
protected void InsertChange(object sender, EventArgs e) { ShiftsEmployee se = new ShiftsEmployee(); int emp = Convert.ToInt32((string)Session["userID"]); string temp = DropDownList1.SelectedValue; int shift = Convert.ToInt32(temp.Substring(0, 2)); string type = temp.Substring(2); int numEff = se.insertSwitch(emp, shift, type); DropDownList1.Items.Clear(); DropDownList2.Items.Clear(); DropDownList3.Items.Clear(); ShiftEmployee(); Changes(); }
protected void ApproveSwitch(object sender, EventArgs e) { ShiftsEmployee se = new ShiftsEmployee(); int empTake = Convert.ToInt32((string)Session["userID"]); string temp = DropDownList3.SelectedValue; string[] tempArr = DropDownList3.SelectedItem.Text.Split(' '); int empAsk = Convert.ToInt32(tempArr[2]); int shift = Convert.ToInt32(temp.Substring(0, 2)); string type = temp.Substring(2); int numEff = 0; if (empAsk != empTake) { numEff = se.approveSwitch(empTake, empAsk, shift, type); } DropDownList1.Items.Clear(); DropDownList2.Items.Clear(); DropDownList3.Items.Clear(); ShiftEmployee(); Changes(); }
protected void ShiftEmployee() { ShiftsEmployee se = new ShiftsEmployee(); List <string> listE = new List <string>(); List <string> listE2 = new List <string>(); int emp = Convert.ToInt32((string)Session["userID"]); string tempList = se.getShiftsAfterEditing(emp); string[] arrayList = tempList.Split('/'); listE = arrayList[0].Split(',').ToList <string>(); foreach (string shift in listE) { ListItem l = new ListItem(); if (shift == "11") { l = new ListItem("ראשון בוקר (שבוע הבא)", "11n"); } else if (shift == "12") { l = new ListItem("ראשון אמצע (שבוע הבא)", "12n"); } else if (shift == "13") { l = new ListItem("ראשון ערב (שבוע הבא)", "13n"); } else if (shift == "21") { l = new ListItem("שני בוקר (שבוע הבא)", "21n"); } else if (shift == "22") { l = new ListItem("שני אמצע (שבוע הבא)", "22n"); } else if (shift == "23") { l = new ListItem("שני ערב (שבוע הבא)", "22n"); } else if (shift == "31") { l = new ListItem("שלישי בוקר (שבוע הבא)", "32n"); } else if (shift == "32") { l = new ListItem("שלישי אמצע (שבוע הבא)", "32n"); } else if (shift == "33") { l = new ListItem("שלישי ערב (שבוע הבא)", "32n"); } else if (shift == "41") { l = new ListItem("רביעי בוקר (שבוע הבא)", "42n"); } else if (shift == "42") { l = new ListItem("רביעי אמצע (שבוע הבא)", "42n"); } else if (shift == "43") { l = new ListItem("רביעי ערב (שבוע הבא)", "42n"); } else if (shift == "51") { l = new ListItem("חמישי בוקר (שבוע הבא)", "51n"); } else if (shift == "52") { l = new ListItem("חמישי אמצע (שבוע הבא)", "52n"); } else if (shift == "53") { l = new ListItem("חמישי ערב (שבוע הבא)", "53n"); } else if (shift == "61") { l = new ListItem("שישי בוקר (שבוע הבא)", "61n"); } else if (shift == "71") { l = new ListItem("צאת שבת (שבוע הבא)", "73n"); } DropDownList1.Items.Add(l); } if (arrayList.Length > 1) { listE2 = arrayList[1].Split(',').ToList <string>(); foreach (string shift in listE2) { ListItem l = new ListItem(); if (shift == "11") { l = new ListItem("ראשון בוקר (השבוע)", "11w"); } else if (shift == "12") { l = new ListItem("ראשון אמצע (השבוע)", "12w"); } else if (shift == "13") { l = new ListItem("ראשון ערב (השבוע)", "13w"); } else if (shift == "21") { l = new ListItem("שני בוקר (השבוע)", "21w"); } else if (shift == "22") { l = new ListItem("שני אמצע (השבוע)", "22w"); } else if (shift == "23") { l = new ListItem("שני ערב (השבוע)", "22w"); } else if (shift == "31") { l = new ListItem("שלישי בוקר (השבוע)", "32w"); } else if (shift == "32") { l = new ListItem("שלישי אמצע (השבוע)", "32w"); } else if (shift == "33") { l = new ListItem("שלישי ערב (השבוע)", "32w"); } else if (shift == "41") { l = new ListItem("רביעי בוקר (השבוע)", "42w"); } else if (shift == "42") { l = new ListItem("רביעי אמצע (השבוע)", "42w"); } else if (shift == "43") { l = new ListItem("רביעי ערב (השבוע)", "42w"); } else if (shift == "51") { l = new ListItem("חמישי בוקר (השבוע)", "51w"); } else if (shift == "52") { l = new ListItem("חמישי אמצע (השבוע)", "52w"); } else if (shift == "53") { l = new ListItem("חמישי ערב (השבוע)", "53w"); } else if (shift == "61") { l = new ListItem("שישי בוקר (השבוע)", "61w"); } else if (shift == "71") { l = new ListItem("צאת שבת (השבוע)", "73w"); } DropDownList1.Items.Add(l); } } }
protected void LoadAlgorithm(object sender, EventArgs e) { ShiftsEmployee shiftEmp = new ShiftsEmployee(); List <ShiftsEmployee> shiftEmpList = shiftEmp.GetShiftsList(); Employee emp = new Employee(); List <Employee> empL = emp.getEmployeeList(); foreach (ShiftsEmployee shift in shiftEmpList) { HtmlGenericControl divShift = new HtmlGenericControl("button"); divShift.Attributes["class"] = "btn btn-light"; foreach (Employee empT in empL) { if (shift.Title == empT.First_name) { divShift.ID = empT.User_name + "_" + shift.Type; } } divShift.Attributes.CssStyle.Add("width", "80px"); divShift.Attributes.CssStyle.Add("margin-bottom", "2px"); divShift.InnerHtml = shift.Title + " <img src='img/delete.png' style='height: 15px; '/>"; if (shift.Type == 11) { PlaceHolder11.Controls.Add(divShift); continue; } else if (shift.Type == 21) { PlaceHolder21.Controls.Add(divShift); continue; } else if (shift.Type == 31) { PlaceHolder31.Controls.Add(divShift); continue; } else if (shift.Type == 41) { PlaceHolder41.Controls.Add(divShift); continue; } else if (shift.Type == 51) { PlaceHolder51.Controls.Add(divShift); continue; } else if (shift.Type == 61) { PlaceHolder61.Controls.Add(divShift); continue; } else if (shift.Type == 71) { PlaceHolder71.Controls.Add(divShift); continue; } else if (shift.Type == 12) { PlaceHolder12.Controls.Add(divShift); continue; } else if (shift.Type == 22) { PlaceHolder22.Controls.Add(divShift); continue; } else if (shift.Type == 32) { PlaceHolder32.Controls.Add(divShift); continue; } else if (shift.Type == 42) { PlaceHolder42.Controls.Add(divShift); continue; } else if (shift.Type == 52) { PlaceHolder52.Controls.Add(divShift); continue; } else if (shift.Type == 62) { PlaceHolder62.Controls.Add(divShift); continue; } else if (shift.Type == 72) { PlaceHolder72.Controls.Add(divShift); continue; } else if (shift.Type == 13) { PlaceHolder13.Controls.Add(divShift); continue; } else if (shift.Type == 23) { PlaceHolder23.Controls.Add(divShift); continue; } else if (shift.Type == 33) { PlaceHolder33.Controls.Add(divShift); continue; } else if (shift.Type == 43) { PlaceHolder43.Controls.Add(divShift); continue; } else if (shift.Type == 53) { PlaceHolder53.Controls.Add(divShift); continue; } else if (shift.Type == 63) { PlaceHolder63.Controls.Add(divShift); continue; } else if (shift.Type == 73) { PlaceHolder73.Controls.Add(divShift); continue; } } EmployeeList.Controls.Clear(); foreach (Employee empTemp in empL) { HtmlGenericControl divEmpl = new HtmlGenericControl("div"); divEmpl.Attributes["class"] = "btn list"; divEmpl.ID = empTemp.First_name; divEmpl.Attributes["draggable"] = "true"; divEmpl.Attributes["ondragstart"] = "drag(event)"; string list = ""; foreach (ShiftsEmployee item in empTemp.Last_shift) { if (list == "") { list = Convert.ToString(item.Type); } else { list += "0" + Convert.ToString(item.Type); } } divEmpl.Attributes["onmouseover"] = "employeePerfernce(" + list + ")"; divEmpl.Attributes["onmouseout"] = "clearShiftTable()"; divEmpl.InnerHtml = empTemp.First_name + " " + empTemp.Last_name; int counter = 0; foreach (ShiftsEmployee shift in shiftEmpList) { if (shift.Title == empTemp.First_name) { counter++; } } if (counter > empTemp.Minimum) { divEmpl.InnerHtml += " <span class='badge badge-pill badge-primary tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span><span id='" + empTemp.User_name + "'>" + counter + "<span></span>"; } else if (counter == empTemp.Minimum) { divEmpl.InnerHtml += " <span class='badge badge-pill badge-success tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span><span id='" + empTemp.User_name + "'>" + counter + "<span></span>"; } else if (counter > empTemp.Minimum) { divEmpl.InnerHtml += " <span class='badge badge-pill badge-warning tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span><span id='" + empTemp.User_name + "'>" + counter + "<span></span>"; } else if (counter == 0) { divEmpl.InnerHtml += " <span class='badge badge-pill badge-danger tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span><span id='" + empTemp.User_name + "'>" + 0 + "<span></span>"; } divEmpl.ID = Convert.ToString(empTemp.First_name + "_" + empTemp.Last_name + "_" + empTemp.User_name); EmployeeList.Controls.Add(divEmpl); } }
protected void Changes() { ShiftsEmployee se = new ShiftsEmployee(); List <string> listE = new List <string>(); listE = se.getChanges(); foreach (string shift in listE) { string[] temp = shift.Split('|'); string whenTemp = temp[2]; string when = ""; if (whenTemp == "w") when = " (השבוע)"; else { when = " (שבוע הבא)"; } ListItem l = new ListItem(); ListItem l2 = new ListItem(); if (temp[0] == "11") { l = new ListItem("ראשון בוקר " + temp[1] + when, "11" + whenTemp); } else if (temp[0] == "12") { l = new ListItem("ראשון אמצע " + temp[1] + when, "12" + whenTemp); } else if (temp[0] == "13") { l = new ListItem("ראשון ערב " + temp[1] + when, "13" + whenTemp); } else if (temp[0] == "21") { l = new ListItem("שני בוקר " + temp[1] + when, "21" + whenTemp); } else if (temp[0] == "22") { l = new ListItem("שני אמצע " + temp[1] + when, "22" + whenTemp); } else if (temp[0] == "23") { l = new ListItem("שני ערב " + temp[1] + when, "22" + whenTemp); } else if (temp[0] == "31") { l = new ListItem("שלישי בוקר " + temp[1] + when, "32" + whenTemp); } else if (temp[0] == "32") { l = new ListItem("שלישי אמצע " + temp[1] + when, "32" + whenTemp); } else if (temp[0] == "33") { l = new ListItem("שלישי ערב " + temp[1] + when, "32" + whenTemp); } else if (temp[0] == "41") { l = new ListItem("רביעי בוקר " + temp[1] + when, "42" + whenTemp); } else if (temp[0] == "42") { l = new ListItem("רביעי אמצע " + temp[1] + when, "42" + whenTemp); } else if (temp[0] == "43") { l = new ListItem("רביעי ערב " + temp[1] + when, "42" + whenTemp); } else if (temp[0] == "51") { l = new ListItem("חמישי בוקר " + temp[1] + when, "51" + whenTemp); } else if (temp[0] == "52") { l = new ListItem("חמישי אמצע " + temp[1] + when, "52" + whenTemp); } else if (temp[0] == "53") { l = new ListItem("חמישי ערב " + temp[1] + when, "53" + whenTemp); } else if (temp[0] == "61") { l = new ListItem("שישי בוקר " + temp[1] + when, "61" + whenTemp); } else if (temp[0] == "71") { l = new ListItem("צאת שבת " + temp[1] + when, "73" + whenTemp); } if (temp[3] == "0") { DropDownList2.Items.Add(l); } else { DropDownList3.Items.Add(l); } } }
public string getShifts() { Employee empl = new Employee(); //List<string> tempList = new List<string>(); Shift thisweekshift = new Shift(); Shift tempSh = new Shift(); thisweekshift = tempSh.getShiftObjects(); List <Employee> employee = empl.getEmployeeObjects(); List <ShiftsEmployee> tempSE = new List <ShiftsEmployee>(); //Create Sort List to Make the Different Algoritm int plusN = 1; SortedList <double, Employee> sl = new SortedList <double, Employee>(); foreach (Employee emp in employee) { Random rnd = new Random(); double plus = Convert.ToDouble(rnd.Next(1, 50)) * 0.0001; if (emp.First_name != "בר") { double keys = (double)emp.Minimum / (emp.Last_shift.Count()); sl.Add(keys + plus * plusN, emp); plusN++; } else { sl.Add(0, emp); } } //Create new List of employees List <Employee> employeeList = new List <Employee>(); foreach (KeyValuePair <double, Employee> item in sl) { if (item.Value.First_name != "בר") { employeeList.Add(item.Value); } } //Adding the mananger the the end of list foreach (KeyValuePair <double, Employee> item in sl) { if (item.Value.First_name == "בר") { employeeList.Add(item.Value); } } //Revese the list employeeList.Reverse(); //////////// //Algoritm// //////////// foreach (Employee emp in employeeList) //Running on employees list { if (emp.Minimum > emp.Have) //Running just on employees who dont have enough shifts { foreach (ShiftsEmployee shift in emp.Last_shift) //Running in shift list of each employee { for (int i = 0; i < thisweekshift.Possibles.Count; i++) //Running on possible shifts of employees { if (shift.Type == thisweekshift.Shifts[i] && thisweekshift.Possibles[i] > 0) //Match shifts and updating { thisweekshift.Possibles[i] -= 1; emp.Have++; tempSE.Add(shift); } } } } } //Checking that all shifts are done employeeList.Reverse(); for (int i = 0; i < thisweekshift.Possibles.Count; i++) //Running on possible shifts of employees { if (thisweekshift.Possibles[i] > 0) //Match shifts and updating { foreach (Employee emp in employeeList) { foreach (ShiftsEmployee shift in emp.Last_shift) { if (shift.Type == thisweekshift.Shifts[i] && thisweekshift.Possibles[i] > 0) //Match shifts and updating { int temp = 0; foreach (ShiftsEmployee shifts in tempSE) { if (shifts.Title == emp.First_name && shifts.Type == thisweekshift.Shifts[i]) { temp++; } } if (temp == 0) { thisweekshift.Possibles[i] -= 1; emp.Have++; tempSE.Add(shift); } } } } } } ShiftsEmployee SE = new ShiftsEmployee(); string p = SE.writeToJson(tempSE); return(p); }
protected void XmlReader(object sender, EventArgs e) { //קבלת הנתונים List <Employee> l = new List <Employee>(); String xmlFile = Server.MapPath("~/App_Code/Rikushet.xml"); XPathNavigator nav; XPathDocument docNav; docNav = new XPathDocument(xmlFile); nav = docNav.CreateNavigator(); XPathNodeIterator NodeIter; NodeIter = nav.Select("/Employees/employee"); while (NodeIter.MoveNext()) { Employee tempE = new Employee(); tempE.First_name = Convert.ToString(NodeIter.Current.SelectSingleNode("first_name").Value); tempE.Last_name = Convert.ToString(NodeIter.Current.SelectSingleNode("last_name").Value); tempE.User_name = Convert.ToInt32(NodeIter.Current.SelectSingleNode("user_name").Value); tempE.Minimum = Convert.ToInt32(NodeIter.Current.SelectSingleNode("minimum").Value); tempE.Password = Convert.ToString(NodeIter.Current.SelectSingleNode("password").Value); tempE.Type = Convert.ToString(NodeIter.Current.SelectSingleNode("type").Value); tempE.Branch = Convert.ToString(NodeIter.Current.SelectSingleNode("branch").Value); tempE.Have = 0; List <ShiftsEmployee> EmplL = new List <ShiftsEmployee>(); string temp = Convert.ToString(NodeIter.Current.SelectSingleNode("shiftsEmployees").Value); string[] tempString = temp.Split(','); foreach (string item in tempString) //כל העדפה של עובד תשמר באובייקט מיטחד של משמרת { ShiftsEmployee tempSE2 = new ShiftsEmployee(); tempSE2.Title = tempE.First_name; tempSE2.Type = Convert.ToInt32(item); EmplL.Add(tempSE2); } tempE.Last_shift = EmplL; l.Add(tempE); } Shift thisweekshift = new Shift(); Shift tempSh = new Shift(); thisweekshift = tempSh.getShiftSetting(); List <Employee> employee = l; List <ShiftsEmployee> tempSE = new List <ShiftsEmployee>(); //Create Sort List to Make the Different Algoritm int plusN = 1; SortedList <double, Employee> sl = new SortedList <double, Employee>(); foreach (Employee em in employee) { Random rnd = new Random(); double plus = Convert.ToDouble(rnd.Next(1, 50)) * 0.0001; if (em.First_name != "בר") { double keys = (double)em.Minimum / (em.Last_shift.Count()); sl.Add(keys + plus * plusN, em); plusN++; } else { sl.Add(0, em); } } //Create new List of employees List <Employee> employeeList = new List <Employee>(); foreach (KeyValuePair <double, Employee> item in sl) { if (item.Value.First_name != "בר") { employeeList.Add(item.Value); } } //Adding the mananger the the end of list foreach (KeyValuePair <double, Employee> item in sl) { if (item.Value.First_name == "בר") { employeeList.Add(item.Value); } } //Revese the list employeeList.Reverse(); //////////// //Algoritm// //////////// foreach (Employee emp2 in employeeList) //Running on employees list { if (emp2.Minimum > emp2.Have) //Running just on employees who dont have enough shifts { foreach (ShiftsEmployee shift in emp2.Last_shift) //Running in shift list of each employee { for (int i = 0; i < thisweekshift.Possibles.Count; i++) //Running on possible shifts of employees { if (shift.Type == thisweekshift.Shifts[i] && thisweekshift.Possibles[i] > 0) //Match shifts and updating { thisweekshift.Possibles[i] -= 1; emp2.Have++; tempSE.Add(shift); } } } } } //Checking that all shifts are done for (int i = 0; i < thisweekshift.Possibles.Count; i++) //Running on possible shifts of employees { if (thisweekshift.Possibles[i] > 0) //Match shifts and updating { foreach (Employee emp3 in employeeList) { foreach (ShiftsEmployee shift in emp3.Last_shift) { if (shift.Type == thisweekshift.Shifts[i] && thisweekshift.Possibles[i] > 0) //Match shifts and updating { int temp = 0; foreach (ShiftsEmployee shifts in tempSE) { if (shifts.Title == emp3.First_name && shifts.Type == thisweekshift.Shifts[i]) { temp++; } } if (temp == 0) { thisweekshift.Possibles[i] -= 1; emp3.Have++; tempSE.Add(shift); } } } } } } PlaceHolder11.Controls.Clear(); PlaceHolder21.Controls.Clear(); PlaceHolder31.Controls.Clear(); PlaceHolder41.Controls.Clear(); PlaceHolder51.Controls.Clear(); PlaceHolder61.Controls.Clear(); PlaceHolder71.Controls.Clear(); PlaceHolder12.Controls.Clear(); PlaceHolder22.Controls.Clear(); PlaceHolder32.Controls.Clear(); PlaceHolder42.Controls.Clear(); PlaceHolder52.Controls.Clear(); PlaceHolder62.Controls.Clear(); PlaceHolder72.Controls.Clear(); PlaceHolder13.Controls.Clear(); PlaceHolder23.Controls.Clear(); PlaceHolder33.Controls.Clear(); PlaceHolder43.Controls.Clear(); PlaceHolder53.Controls.Clear(); PlaceHolder63.Controls.Clear(); PlaceHolder73.Controls.Clear(); EmployeeList.Controls.Clear(); Employee emp = new Employee(); List <Employee> empL = emp.getEmployeeList(); foreach (ShiftsEmployee shift in tempSE) { HtmlGenericControl divShift = new HtmlGenericControl("button"); divShift.Attributes["class"] = "btn btn-light"; foreach (Employee empT in empL) { if (shift.Title == empT.First_name) { divShift.ID = empT.User_name + "_" + shift.Type; } } divShift.Attributes.CssStyle.Add("width", "80px"); divShift.Attributes.CssStyle.Add("margin-bottom", "2px"); divShift.InnerHtml = shift.Title + " <img src='img/delete.png' style='height: 15px; '/>"; if (shift.Type == 11) { PlaceHolder11.Controls.Add(divShift); continue; } else if (shift.Type == 21) { PlaceHolder21.Controls.Add(divShift); continue; } else if (shift.Type == 31) { PlaceHolder31.Controls.Add(divShift); continue; } else if (shift.Type == 41) { PlaceHolder41.Controls.Add(divShift); continue; } else if (shift.Type == 51) { PlaceHolder51.Controls.Add(divShift); continue; } else if (shift.Type == 61) { PlaceHolder61.Controls.Add(divShift); continue; } else if (shift.Type == 71) { PlaceHolder71.Controls.Add(divShift); continue; } else if (shift.Type == 12) { PlaceHolder12.Controls.Add(divShift); continue; } else if (shift.Type == 22) { PlaceHolder22.Controls.Add(divShift); continue; } else if (shift.Type == 32) { PlaceHolder32.Controls.Add(divShift); continue; } else if (shift.Type == 42) { PlaceHolder42.Controls.Add(divShift); continue; } else if (shift.Type == 52) { PlaceHolder52.Controls.Add(divShift); continue; } else if (shift.Type == 62) { PlaceHolder62.Controls.Add(divShift); continue; } else if (shift.Type == 72) { PlaceHolder72.Controls.Add(divShift); continue; } else if (shift.Type == 13) { PlaceHolder13.Controls.Add(divShift); continue; } else if (shift.Type == 23) { PlaceHolder23.Controls.Add(divShift); continue; } else if (shift.Type == 33) { PlaceHolder33.Controls.Add(divShift); continue; } else if (shift.Type == 43) { PlaceHolder43.Controls.Add(divShift); continue; } else if (shift.Type == 53) { PlaceHolder53.Controls.Add(divShift); continue; } else if (shift.Type == 63) { PlaceHolder63.Controls.Add(divShift); continue; } else if (shift.Type == 73) { PlaceHolder73.Controls.Add(divShift); continue; } } EmployeeList.Controls.Clear(); foreach (Employee empTemp in empL) { HtmlGenericControl divEmpl = new HtmlGenericControl("div"); divEmpl.Attributes["class"] = "btn list"; divEmpl.ID = empTemp.First_name; divEmpl.Attributes["draggable"] = "true"; divEmpl.Attributes["ondragstart"] = "drag(event)"; string list = ""; foreach (ShiftsEmployee item in empTemp.Last_shift) { if (list == "") { list = Convert.ToString(item.Type); } else { list += "," + Convert.ToString(item.Type); } } divEmpl.Attributes["onmouseover"] = "employeePerfernce(" + list + ")"; divEmpl.Attributes["onmouseout"] = "clearShiftTable()"; divEmpl.InnerHtml = empTemp.First_name + " " + empTemp.Last_name; int counter = 0; foreach (ShiftsEmployee shift in tempSE) { if (shift.Title == empTemp.First_name) { counter++; } } if (counter > 0) { divEmpl.InnerHtml += " <span class='badge badge-pill badge-danger tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span>" + counter + "</span>"; } else { divEmpl.InnerHtml += " <span class='badge badge-pill badge-danger tooltipC'> <span class='tooltiptext'>" + empTemp.Minimum + " משמרות</span>" + counter + "</span>"; } divEmpl.ID = Convert.ToString(empTemp.First_name + "_" + empTemp.Last_name + "_" + empTemp.User_name); EmployeeList.Controls.Add(divEmpl); } }