public static DaySchedule GetDaySchedule(ref SerializableDictionary <DateTime, DaySchedule> staffCalendar, DateTime date2Add) { try { //clean dateTime parameter to only show date DateTime cleanDate = date2Add.Date; DaySchedule resultDaySchedule = null; //TryGet daySchedule for giving date if (staffCalendar.TryGetValue(cleanDate, out resultDaySchedule)) { //add daySchedule to local variable // SerializableDictionary<int, string> staffDaySchedule = resultDaySchedule.daySchedule; //add to daySchedule and return return(resultDaySchedule); } //this will be null if gets here return(resultDaySchedule); } catch (Exception ex) { System.Diagnostics.Debug.Print("<h2>BLL.AgendaBLL.GetDaySchedule(x2)</h2>\n" + ex.ToString() + "\n" + ex.InnerException + "\n" + ex.Message); ExceptionHandling.LogException(ref ex); return(null); } }//end AddBooking
}//end AddBooking public static bool?IsStaffBusy(ref SerializableDictionary <DateTime, DaySchedule> staffCalendar, DateTime date2Check, int time2Check) { try { //source http://www.dotnetperls.com/dictionary //ie: d.Remove("cat"); // Removes cat. DaySchedule resultDaySchedule = null; DaySchedule newDaySchedule = new DaySchedule();//(isTest: true); //clean dateTime parameter to only show date DateTime cleanDate = date2Check.Date; //try to find if staffCalendar has this date set on it. if (staffCalendar.TryGetValue(cleanDate, out resultDaySchedule)) // Returns true or false. { //if true fills in newDaySchedule with corresponding value of given key //print current date to check System.Diagnostics.Debug.Print("Current Day being checked is: " + cleanDate.ToString()); //check day schedule status return(DaySchedule.IsStaffBusy(newDaySchedule.daySchedule, time2Check)); } //current day doesnt exist on staff calendar so add it a new day shedule for the given date //R staffCalendar[cleanDate] = newDaySchedule; return(false); } catch (Exception ex) { System.Diagnostics.Debug.Print("<h2>BLL.AgendaBLL.IsStaffBusy(x3)</h2>\n" + ex.ToString() + "\n" + ex.InnerException + "\n" + ex.Message); ExceptionHandling.LogException(ref ex); return(null); } }//end IsStaffBusy
}//end CreateDayScheduleXML /// <summary> /// Adds a new appointment child to DailySchedule XML /// </summary> /// <param name="fileName"></param> /// <param name="date"></param> /// <param name="time"></param> /// <param name="isBusy"></param> /// <returns></returns> public static XmlDocument AddApptNode2DayScheduleXML(string fileName, DateTime date, int time, bool isBusy = true) { try { //set booking status to BUSY string bookStatus = DaySchedule.GetDayStatusEnumString(DayStatusEnum.BUSY); if (!isBusy) { //set booking status to AVAILABLE bookStatus = DaySchedule.GetDayStatusEnumString(DayStatusEnum.AVAILABLE); } //OpenFile handles new file XmlDocument xdoc = QueryXML.OpenFile(fileName); xdoc = QueryXML.AddChild2Root(filename: fileName, childName: "Booking"); xdoc = QueryXML.AddChild2LastChild(filename: fileName, childName: "Time", childIValue: time.ToString()); xdoc = QueryXML.AddChild2LastChild(filename: fileName, childName: "Status", childIValue: bookStatus); //save document xdoc.Save(fileName); return(xdoc); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end AddAppt2DayScheduleXML
}//end AddAppt2DayScheduleXML /// <summary> ///Returns the XMLDocument created from staff daily Shedule /// it returns fileName by default /// </summary> /// <param name="employee"></param> /// <param name="filePath"></param> /// <param name="date"></param> /// <param name="isFileNameReq"></param> /// <returns></returns> public static XmlDocument CreateXMLFromDaySchedule(EmployeeBLL employee, string filePath, DateTime date) { try { //get staff's agenda calendar SerializableDictionary <DateTime, DaySchedule> staffCalendar = employee.agenda.staffCalendar; //get staff day schedule for given day DaySchedule employeeDaySchedule = AgendaBLL.GetDaySchedule(ref staffCalendar, date); //create XML file XmlDocument xdoc = new XmlDocument(); string fileName = DayScheduleXML.CreateDayScheduleXML(filePath, employee.agenda.ID, date, isFileNameReq: true); if (employeeDaySchedule != null) { //loop through day schedule. ie: each hr and 1/h of the staff agenda foreach (var pair in employeeDaySchedule.daySchedule) { //get time and availability int tempTime = pair.Key; //ie: 1100, 1130 string tempTimeStatus = pair.Value; //ie BUSY, AVAILABLE System.Diagnostics.Debug.Print("Key: {0}, Value: {1}", tempTime, tempTimeStatus); //check if staff is busy if (pair.Value == DaySchedule.GetDayStatusEnumString(DayStatusEnum.BUSY)) { //Add child to xml / appointment xdoc = DayScheduleXML.AddApptNode2DayScheduleXML(fileName, date, tempTime); } } //endforloop } //endif else { //staff daySchedule is empty so enable all buttons System.Diagnostics.Debug.Print("<h2>BLL.DayScheduleXML.CreateXMLFromDaySchedule()</h2> \t staff daySchedule is empty!"); return(null); } //return XML file return(xdoc); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end CreateDayScheduleXML
}//end AddBooking public static bool AddBooking(ref SerializableDictionary <DateTime, DaySchedule> staffCalendar, DateTime date2Add, int time2Add) { try { bool bookingAdded = false; bool isStaffBusy = false; //clean dateTime parameter to only show date DateTime cleanDate = date2Add.Date; DaySchedule newDaySchedule = new DaySchedule();//(isTest: true); DaySchedule resultDaySchedule = null; //check staff isnt already busy at the given date and time //NB IsStaffBusy could be null then an cast error is going to occur here 19/7/16, must test isStaffBusy = (bool)IsStaffBusy(ref staffCalendar, cleanDate, time2Add); //check whether a dailySchedule exists for the given date if (!staffCalendar.TryGetValue(cleanDate, out resultDaySchedule)) { //create one if is doesnt exist staffCalendar[cleanDate] = newDaySchedule; } if (!isStaffBusy) { //TryGet daySchedule for giving date if (staffCalendar.TryGetValue(cleanDate, out resultDaySchedule)) { //add daySchedule to local variable SerializableDictionary <int, string> staffDaySchedule = resultDaySchedule.daySchedule; //add to daySchedule and return return(DaySchedule.AddBooking(ref staffDaySchedule, time2Add)); } } //shouldnt get here return(bookingAdded); } catch (Exception ex) { System.Diagnostics.Debug.Print("<h2>BLL.AgendaBLL.AddBooking(x3)</h2>\n" + ex.ToString() + "\n" + ex.InnerException + "\n" + ex.Message); ExceptionHandling.LogException(ref ex); return(false); } }//end AddBooking
/// <summary> /// Get test installation object. /// </summary> /// <returns></returns> /// <remarks></remarks> public static Installation GetTestInstallation() { try { Installation i = new Installation(); //Company var _with2 = i.Company; _with2.ID = 1; _with2.domain = "TESTING Ltd"; _with2.industry = "Net Business"; _with2.natureOfBusiness = 99999; _with2.regNumb = "9372370-2"; _with2.dateIncorporated = (DateTime)Utils.GetDateFromString2("04/08/2016 07:00:00"); _with2.url = "www.RachieHolding.com"; _with2.isVATreg = true; _with2.VATnumb = "9234902-0"; _with2.businessAddress = new ContactDetailsBLL(); //client (main company contact) var _with1 = _with2.mainClientContact; _with1.ID = 1; _with1.title = Person.MRS; _with1.firstName = "ME"; _with1.lastName = "McSantos"; _with1.role = (byte)RolesEnum.CLIENT; _with1.aspnetUserID = (Guid)Utils.GetTestASP_UserID(); //client Contact Details var _with11 = _with1.contactDetail; _with11.ID = 3; _with11.address = "rua 23 qd 46 lot 28"; _with11.city = "Azerbejan"; _with11.postCode = "88402-445"; _with11.country = "South Africa"; _with11.landline = "9047201-02348578"; _with11.mobile = "234532455465"; _with11.email = "*****@*****.**"; _with11.dateCreated = Utils.GetDatetimeNOW(); _with11.dateUpdated = (DateTime)Utils.GetDateFromString("01/12/2010 10:04:08"); //employees var _with3 = i.Employees; EmployeeBLL oi1 = new EmployeeBLL(Person.MRS, "RUTH", "Simpson", "*****@*****.**", (Guid)Utils.GetTestASP_UserID()); oi1.ID = 1; oi1.agenda.ID = 1; //NB AgendaID must be valid to save xml to DB DaySchedule newTestDaySchedule = new DaySchedule(isTest: true); oi1.agenda.staffCalendar.Add(Utils.GetDatetimeNOW().Date, newTestDaySchedule); _with3.Add(oi1); //staff 2 EmployeeBLL oi2 = new EmployeeBLL(Person.MS, "Lorenzo", "Victor", new ContactDetailsBLL(), "34802342-289", "developer", new AgendaBLL(), (Guid)Utils.GetTestASP_UserID()); oi2.ID = 2; oi2.agenda.ID = 2; //NB AgendaID must be valid to save xml to DB DaySchedule newTestDaySchedule2 = new DaySchedule(isTest: true); oi2.agenda.staffCalendar.Add(Utils.GetDatetimeNOW().Date.AddDays(1), newTestDaySchedule); _with3.Add(oi2); //staff 3 EmployeeBLL oi3 = new EmployeeBLL(Person.MR, "Alves", "Thomas", new ContactDetailsBLL(), "34802342-289", "developer", new AgendaBLL(), (Guid)Utils.GetTestASP_UserID()); oi3.ID = 3; oi3.agenda.ID = 3; //NB AgendaID must be valid to save xml to DB DaySchedule newTestDaySchedule3 = new DaySchedule(isTest: true); oi3.agenda.staffCalendar.Add(Utils.GetDatetimeNOW().Date.AddDays(2), newTestDaySchedule); _with3.Add(oi3); //services var _with4 = i.Services; ServicesBLL a = new ServicesBLL("service 1", "wrap up without a word", 55, 99.3m); a.ID = 1; ServicesBLL b = new ServicesBLL("service 2", "no no no ", 89, 102236.893m); b.ID = 2; ServicesBLL c = new ServicesBLL("service 3", "FFS84857 983*33h", byte.MaxValue, decimal.MaxValue); c.ID = 3; ServicesBLL d = new ServicesBLL("service 4", "wrap up again", byte.MinValue, decimal.MinValue); d.ID = 4; _with4.Add(a); _with4.Add(b); _with4.Add(c); _with4.Add(d); //services Provided By Staff var _with5 = i.ServicesProvidedByStaff; _with5 = null; return(i); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }
/// <summary> /// MUST review 11/7/16 /// </summary> /// <param name="i"></param> /// <param name="company"></param> public static Installation PopulateInstalationObjFromDB(ref Installation i, int?companyID, string iSumXMLfileName) { try { if (i == null) { i = new Installation(); //timestamp i.Timestamp = Utils.GetDatetimeNOW(); } //------ company --------- //get company dataTable var company = CompanyBLL.GetCompanyByID(companyID); //.GetAllCompanies();?? if (company.Count > 0) //==1 //get ----summary installation xml----- { XmlDocument iXmlDoc = CompanyBLL.GetInstallSummanyXMLDoc(companyID, iSumXMLfileName); //get ----company contact Details ----- dataTable int coContactDetID = company.Rows[0].Field <int>(8); var coContactDet = ContactDetailsBLL.GetContactDetailByID(coContactDetID); //populate an instance of contactDetBLL var _with11 = coContactDet.Rows[0]; ContactDetailsBLL coContactBLL = new ContactDetailsBLL(_with11.Field <string>(1), _with11.Field <string>(3), _with11.Field <string>(2), _with11.Field <string>(4), _with11.Field <string>(5), _with11.Field <string>(6), _with11.Field <string>(7)); coContactBLL.ID = _with11.Field <int>(0); //polulate an instance of companyBLL var _with1 = company.Rows[0]; CompanyBLL coBLL = new CompanyBLL(_with1.Field <string>(1), _with1.Field <string>(2), _with1.Field <int?>(3), _with1.Field <string>(4), _with1.Field <DateTime?>(5), _with1.Field <string>(6), _with1.Field <bool?>(9), _with1.Field <string>(10)); coBLL.ID = _with1.Field <int>(0);//same as companyID //add contact details to coBLL coBLL.businessAddress = coContactBLL; //------- SAVE INSTALLATION XML SUMMARY TO SESSION ------------ i.Company.iSummaryXML = iXmlDoc; //foreign keys int clientID = _with1.Field <int>(7); //------ Client --------- //get client dataTable var client = ClientBLL.GetClientByID(clientID);//GetAllClients(); //get ---- client contact ------dataTable int cltContactDetID = client.Rows[0].Field <int>(4); var cltContactDet = ContactDetailsBLL.GetContactDetailByID(cltContactDetID); //populate an instance of contactDetBLL var _with21 = cltContactDet.Rows[0]; ContactDetailsBLL clientContactBLL = new ContactDetailsBLL(_with21.Field <string>(1), _with21.Field <string>(3), _with21.Field <string>(2), _with21.Field <string>(4), _with21.Field <string>(5), _with21.Field <string>(6), _with21.Field <string>(7)); clientContactBLL.ID = _with21.Field <int>(0); //Populate clientBLL var _with2 = client.Rows[0]; ClientBLL clientBLL = new ClientBLL(_with2.Field <string>(1), _with2.Field <string>(2), _with2.Field <string>(3), clientContactBLL, _with2.Field <Guid>(9)); clientBLL.ID = _with2.Field <int>(0); //add client to company coBLL.mainClientContact = clientBLL; //add to installation i.Company = coBLL; //----------------------------------------------end of company--------------------------------------------------------------------- //------------ Employees -------------- List <int> thisCoEmployees = AppSettings.GetIDsList(iSumXmlDoc: iXmlDoc, perform: AppSettings.iEmpID); //loop through all employees registered to this company foreach (int staffID in thisCoEmployees) { //get employee dataTable var employees = EmployeeBLL.GetEmployeeByID(staffID); // Loop through all employees foreach (DataRow employee in employees.Rows) { //get ---- employee agenda ------dataTable short staffAgendaID = employee.Field <short>(8); var staffAgenda = AgendaBLL.GetAgendaByID(staffAgendaID); //populate an instance of agendaBLL var _with41 = staffAgenda.Rows[0]; //System.Diagnostics.Debug.Print("staffAgendaID from employee Table is: " + staffAgendaID.ToString() + "staffAgendaID from AGENDA Table is: " + _with41.Field<short>(0).ToString()); AgendaBLL staffAgendaBLL = new AgendaBLL(staffAgendaID, _with41.Field <bool?>(1), _with41.Field <bool?>(2)); staffAgendaBLL.ID = _with41.Field <short>(0); //get ---- employee contact ------dataTable int staffContDetID = employee.Field <int>(4); var staffContDet = ContactDetailsBLL.GetContactDetailByID(staffContDetID); //populate an instance of contactDetBLL var _with31 = cltContactDet.Rows[0]; ContactDetailsBLL staffContactBLL = new ContactDetailsBLL(_with31.Field <string>(1), _with31.Field <string>(3), _with31.Field <string>(2), _with31.Field <string>(4), _with31.Field <string>(5), _with31.Field <string>(6), _with31.Field <string>(7)); staffContactBLL.ID = _with31.Field <int>(0); //Populate staffBLL var _with3 = employee; EmployeeBLL staffBLL = new EmployeeBLL(_with3.Field <string>(1), _with3.Field <string>(2), _with3.Field <string>(3), staffContactBLL, _with3.Field <string>(6), _with3.Field <string>(7), staffAgendaBLL, _with3.Field <Guid>(9)); staffBLL.ID = _with3.Field <int>(0); //add contact detail & agenda to staff // staffBLL.contactDetail = staffContactBLL;//already added on constructor staffBLL.agenda = staffAgendaBLL; //get ---- DailyShedules foreach agenda ------dataTable var curStaffCalendar = staffBLL.agenda.staffCalendar; List <int> bookingTimes = new List <int>(); //get data stored on db var staffAgendaDailyShedules = DailySchedule.GetDailySchedulesByAgendaID(staffAgendaID); // Loop through each dailySchedule on staff's agenda foreach (DataRow dailySchedule in staffAgendaDailyShedules.Rows) { //create a new DayScheduleBLL DaySchedule daySchedBLL = new DaySchedule(); DateTime date = dailySchedule.Field <DateTime>(2); XDocument xDoc = XDocument.Parse(dailySchedule.Field <System.String>(3)); //loopthrough db xml and get a list of "busy times" bookingTimes = DayScheduleXML.GetTimesFromDayScheduleXML(xDoc); //add appts to daySchedBLL foreach (int time in bookingTimes) { //add appts to daySchedBLL bool added = AgendaBLL.AddBooking(ref curStaffCalendar, date, time); System.Diagnostics.Debug.Print("ADDED?\t " + added.ToString()); } // } //end loop daySchedule //add employee to installation i.Employees.Add(staffBLL); } //// endLoop emploee dataTable } // endLoop through all employees //----------------------------------------------end of employees--------------------------------------------------------------------- //------------ services -------------- List <int> thisCoServices = AppSettings.GetIDsList(iSumXmlDoc: iXmlDoc, perform: AppSettings.iServID); //loop through all employees registered to this company foreach (int serviceID in thisCoServices) { //get services dataTable var services = ServicesBLL.GetServiceByID(serviceID); // Loop through all services foreach (DataRow service in services.Rows) { //Populate serviceBLL var _with4 = service; ServicesBLL serviceBLL = new ServicesBLL(_with4.Field <string>(1), _with4.Field <bool?>(2), _with4.Field <bool?>(3), _with4.Field <string>(4), _with4.Field <byte?>(5), _with4.Field <string>(6), _with4.Field <decimal?>(8)); serviceBLL.ID = _with4.Field <int>(0); //add service to installation i.Services.Add(serviceBLL); } } //----------------------------------------------end of services--------------------------------------------------------------------- //------------ End-Users -------------- List <int> thisCoEndUsers = AppSettings.GetIDsList(iSumXmlDoc: iXmlDoc, perform: AppSettings.iuserID); //loop through all employees registered to this company foreach (int endUserID in thisCoEndUsers) { //get staff dataTable var endUsers = EndUserBLL.GetEndUserByID(endUserID); // Loop through all endUsers foreach (DataRow endUser in endUsers.Rows) { //get ---- endUser contact ------dataTable int endUserContDetID = endUser.Field <int>(4); var endUserContDet = ContactDetailsBLL.GetContactDetailByID(endUserContDetID); //populate an instance of contactDetBLL var _with51 = cltContactDet.Rows[0]; ContactDetailsBLL endUserContactBLL = new ContactDetailsBLL(_with51.Field <string>(1), _with51.Field <string>(3), _with51.Field <string>(2), _with51.Field <string>(4), _with51.Field <string>(5), _with51.Field <string>(6), _with51.Field <string>(7)); endUserContactBLL.ID = _with51.Field <int>(0); //Populate endUserBLL var _with5 = endUser; EndUserBLL endUserBLL = new EndUserBLL(_with5.Field <string>(1), _with5.Field <string>(2), _with5.Field <string>(3), endUserContactBLL, _with5.Field <Guid>(9)); endUserBLL.ID = _with5.Field <int>(0); //add service to installation i.EndUsers.Add(endUserBLL); } } //----------------------------------------------end of End-Users--------------------------------------------------------------------- //------------ Appointments -------------- List <int> thisCoAppts = AppSettings.GetIDsList(iSumXmlDoc: iXmlDoc, perform: AppSettings.iApptID); //loop through all employees registered to this company foreach (int apptID in thisCoAppts) { //get appts dataTable var appts = ApptBLL.GetAppointmentByID(apptID); // Loop through all appts foreach (DataRow appt in appts.Rows) { //Populate apptBLL var _with6 = appt; ApptBLL apptBLL = new ApptBLL(_with6.Field <DateTime>(1), _with6.Field <TimeSpan>(2), _with6.Field <int>(3), _with6.Field <int>(4), _with6.Field <string>(5), _with6.Field <string>(6)); apptBLL.ID = _with6.Field <int>(0); //add appt to installation i.Appointments.Add(apptBLL); } } //----------------------------------------------end of Appointments--------------------------------------------------------------------- } return(i); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }