}//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 public static XmlDocument Add_ID_2DayScheduleXML(string fileName, string dayScheduleID) { try { if (!String.IsNullOrEmpty(fileName)) { //OpenFile handles new file XmlDocument xdoc = QueryXML.OpenFile(fileName); //get root element XmlElement root = xdoc.DocumentElement; //add attributes to root node root.SetAttribute(name: "ID", value: dayScheduleID.ToString()); xdoc.AppendChild(root); //save document xdoc.Save(fileName); //return xmlDocument return(xdoc); } //if fileName is invalid return(null); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end AddAppt2DayScheduleXML
}//end AddNode2ISummaryXML public static XmlDocument AddChild2ISummaryXML(string fileName, string perform, string value2Add) { try { //OpenFile handles new file XmlDocument xdoc = QueryXML.OpenFile(fileName, rootName: "Installation"); //declare parent Names string parentName = ""; string childName = ""; string childValue = ""; //set parent Names switch (perform) { case iEmpID: // case operations parentName = "Employees"; childName = iEmpID; childValue = value2Add; break; case iServID: // case operations parentName = "Services"; childName = iServID; childValue = value2Add; break; case iuserID: // case operations parentName = "EndUsers"; childName = iuserID; childValue = value2Add; break; case iApptID: // case operations parentName = "Appointments"; childName = iApptID; childValue = value2Add; break; // default: // Do nothing } xdoc = QueryXML.AddChild2SpecificNode(filename: fileName, parentName: parentName, childName: childName, childIValue: childValue); //save document xdoc.Save(fileName); return(xdoc); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end AddNode2ISummaryXML
/// <summary> /// Either Returns the XMLDocument or full fileName created (including file path) depending on isFileNameReq parameter passed /// by default ist returns the xmlDoc /// </summary> /// <param name="filePath"></param> /// <param name="agendaID"></param> /// <param name="date"></param> /// <param name="isFileNameReq"></param> /// <returns></returns> public static dynamic CreateDayScheduleXML(string filePath, short?agendaID, DateTime date, bool isFileNameReq = false) { try { string staff1stName = EmployeeBLL.GetStaffByAgendaID(agendaID, isFirstName: true); string staffFilePath = filePath + "/" + staff1stName; //ie default filePath: "~/App_Data/DailySchedules/" if (!Directory.Exists(staffFilePath)) { Directory.CreateDirectory(staffFilePath); } string staffDaySchedXMLFileName = staffFilePath + "/" + date.ToString("yyyy_MM_dd") + ".xml"; STAFF_DAYSCHEDULEXML_FILENAME = staffDaySchedXMLFileName; //OpenFile handles creating a new file XmlDocument xdoc = QueryXML.OpenFile(staffDaySchedXMLFileName, rootName: "DailySchedule"); //get root element XmlElement root = xdoc.DocumentElement; //add attributes to root node root.SetAttribute(name: "AgendaID", value: agendaID.ToString()); root.SetAttribute(name: "Date", value: date.ToString("yyyy_MM_dd")); xdoc.AppendChild(root); //save document xdoc.Save(staffDaySchedXMLFileName); //if required on parameter return fileName if (isFileNameReq) { return(staffDaySchedXMLFileName); } //return xmlDocument return(xdoc); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end CreateDayScheduleXML
}//end CreateISummaryXML public static XmlDocument AddNode2ISummaryXML(string fileName, string perform, string value2Add, int index = 0, bool addChild = true) { try { //OpenFile handles new file XmlDocument xdoc = QueryXML.OpenFile(fileName, rootName: "Installation"); //declare parent Names string parentName = ""; string parentValue = ""; string childName = ""; string childValue = ""; bool addparent = true; //only allow 1 child Parent to be added once if (index != 0) { addparent = false; } //set parent Names switch (perform) { case iTimestamp: // case operations parentName = iTimestamp; parentValue = value2Add; addChild = false; break; case iCompanyID: // case operations parentName = iCompanyID; parentValue = value2Add; addChild = false; break; case iEmpID: // case operations parentName = "Employees"; childName = iEmpID; childValue = value2Add; break; case iServID: // case operations parentName = "Services"; childName = iServID; childValue = value2Add; break; case iuserID: // case operations parentName = "EndUsers"; childName = iuserID; childValue = value2Add; break; case iApptID: // case operations parentName = "Appointments"; childName = iApptID; childValue = value2Add; break; // default: // Do nothing } //Add parents to xml file if (addparent) { xdoc = QueryXML.AddChild2Root(filename: fileName, childName: parentName, childIValue: parentValue); } if (addChild) { xdoc = QueryXML.AddChild2LastChild(filename: fileName, childName: childName, childIValue: childValue); } //save document xdoc.Save(fileName); return(xdoc); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end AddNode2ISummaryXML
public static XmlDocument GetInstallationSummaryXML(Installation i, string fileName) { try { //create XML file XmlDocument xmlDoc = QueryXML.OpenFile(fileName); XDocument xDoc = XDocument.Parse(xmlDoc.OuterXml); //get xml file timestamp var xTimestamp = from key in xDoc.Descendants(AppSettings.iTimestamp) select key.Value; DateTime?xFileTimestamp = Utils.GetDateFromString(xTimestamp.ToList().First()); if (xFileTimestamp == null || DateTime.Compare((DateTime)xFileTimestamp, i.Timestamp) != 0) { xmlDoc = CreateNewInstallSummaryXML(fileName); } //get given installation timestamp DateTime curInstTimestamp = i.Timestamp; //add to xml xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iTimestamp, curInstTimestamp.ToString()); //get company int curInstCoID = (int)i.Company.ID; //add to xml xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iCompanyID, curInstCoID.ToString()); // Loop through all employees int tempStaffID = 0; for (int a = 0; a < i.Employees.Count; a++) { EmployeeBLL employee = i.Employees[a]; //get staff ID tempStaffID = (int)employee.ID; //add to xml xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iEmpID, tempStaffID.ToString(), a); } ////still add Employees parent node if users dont exist this point if (i.Employees.Count == 0) { xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iEmpID, String.Empty, 0, addChild: false); } // Loop through all services int tempServID = 0; for (int b = 0; b < i.Services.Count; b++) { ServicesBLL service = i.Services[b]; //get service ID tempServID = (int)service.ID; //add to xml xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iServID, tempServID.ToString(), b); } ////still add services parent node if users dont exist this point if (i.Services.Count == 0) { xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iServID, String.Empty, 0, addChild: false); } // Loop through all endUsers int tempEndUserID = 0; for (int c = 0; c < i.EndUsers.Count; c++) { EndUserBLL endUser = i.EndUsers[c]; //get endUser ID tempEndUserID = (int)endUser.ID; //add to xml xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iuserID, tempEndUserID.ToString(), c); } //still add EndUser parent node if users dont exist this point if (i.EndUsers.Count == 0) { xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iuserID, String.Empty, 0, addChild: false); } // Loop through all appointments int tempApptID = 0; for (int d = 0; d < i.Appointments.Count; d++) { ApptBLL appt = i.Appointments[d]; //get appt ID tempApptID = (int)appt.ID; //add to xml xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iApptID, tempApptID.ToString(), d); } ////still add appt parent node if users dont exist this point if (i.Appointments.Count == 0) { xmlDoc = AddNode2ISummaryXML(fileName, AppSettings.iApptID, String.Empty, 0, addChild: false); } //return XML file return(xmlDoc); } catch (Exception ex) { ExceptionHandling.LogException(ref ex); return(null); } }//end GetInstallationSummaryXML