public void SetCompanyTimes(List <int> items2Set, bool isOpeningtime = true, bool isClosingTime = false)
        {
            try {
                //select enum required
                List <int> selectedEnum = OpeningTime;
                if (isClosingTime)
                {
                    selectedEnum = ClosingTime;
                }

                //loop throught selected list
                // foreach (int time in selectedEnum) {
                for (int i = 0; i < selectedEnum.Count; i++)
                {
                    //set given time
                    selectedEnum[i] = items2Set[i];
                }
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);
            }
        }
        public static bool IsUserOfType(string aspUserName, bool isTypeClient = false, bool isTypeEndUser = false)
        {
            try {
                //get aspUserID
                Guid aspUserID   = (Guid)AppSettings.GetUserIDByUserName(aspUserName);
                var  curUser     = ClientBLL.GetPersonByASPuserID(aspUserID);
                byte curUserRole = 0;

                // get curUser ROLE
                if (curUser != null)
                {
                    curUserRole = (byte)curUser.Rows[0].ItemArray[5];
                }

                //check parameters condition which applys
                if (isTypeClient)
                {
                    if (curUserRole == (byte)RolesEnum.CLIENT)
                    {
                        return(true);
                    }
                }

                if (isTypeEndUser)
                {
                    if (curUserRole == (byte)RolesEnum.END_USER)
                    {
                        return(true);
                    }
                }

                //for now 18/7/16  --- anything else return false
                return(false);
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);
                return(false);
            }
        }
        public static List <string> GetServiceDetails(Installation i, bool isNames = true, bool isDesc = false, bool isDuration = false, bool isPrice = false)
        {
            try {
                //create list to save services items
                List <string> liServNames = new List <string>();

                //loop through services
                foreach (ServicesBLL service in i.Services)
                {
                    //select appropriate detail
                    if (isNames)
                    {
                        //save service name  to new list of string
                        liServNames.Add(service.name);
                    }
                    if (isDesc)
                    {
                        //save service name  to new list of string
                        liServNames.Add(service.description);
                    }
                    if (isDuration)
                    {
                        //save service name  to new list of string
                        liServNames.Add(service.duration.ToString());
                    }
                    if (isPrice)
                    {
                        //save service name  to new list of string
                        liServNames.Add(service.price.ToString());
                    }
                }

                return(liServNames);
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);
                return(null);
            }
        }
        public static List <string> GetAllStaff1stNames()
        {
            try {
                List <string> staffNames = new List <string>();
                //get all employees dataTable
                var allStaff = GetAllEmployees();

                // ... Loop over all rows.
                foreach (DataRow row in allStaff.Rows)
                {
                    // ... Write value of 3rd field as integer.
                    System.Diagnostics.Debug.Print(row.Field <string>(2));
                    //add name to list
                    staffNames.Add(row.Field <string>(2));
                }

                return(staffNames);
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);     return(null);
            }
        }
        /// <summary>
        /// Get object with exception handling settings
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static AppSettings GetAppSettings(string filename)
        {
            try {
                if (!File.Exists(filename))
                {
                    System.Diagnostics.Debug.Print("BLL.AppSettings.GetAppSettings(): EXCEPTION in GetAppSettings: FileNotFoundException: " + filename);
                    throw new FileNotFoundException("Exception in BLL.AppSettings.GetAppSettings()" + filename + " cannot be found /  accessed");
                }

                //load exception handling settings
                //sdkfj assign to this public class
                // dynamic exceptions = GetExceptionHandlingSettings(filename);

                //create new instance of AppSettings
                AppSettings sharedSets = new AppSettings();

                //load the settings XML file
                dynamic doc = XDocument.Load(filename);

                //query XML to get all children of Settings--Setting
                dynamic y = doc.Element(XMLConstants.Settings).Elements(XMLConstants.Setting);

                //create settings object from values in
                var _with2 = sharedSets;
                //SettingsXML
                _with2.SettingsXML = filename;

                ////exception
                //_with2.EmailNotificationsOn = exceptions.EmailNotificationsOn;
                //_with2.RecordToDataBase = exceptions.RecordToDataBase;
                //_with2.ExceptionRecipient = exceptions.ExceptionRecipient;

                ////client
                //_with2.SystemUserID = new Guid(UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.SystemUserID));
                //_with2.ApplicationName = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.ApplicationName);
                //_with2.Client = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.CLIENT);

                //_with2.ClientAsset = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.ClientAsset);
                //_with2.ClientLogo = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.ClientLogo);
                //_with2.ClientUnit = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.ClientUnit);

                ////Q & A filename
                //_with2.QAFilename = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.QAFilename);

                ////units filename
                //_with2.UnitsXMLFilename = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.UnitsXMLFilename);

                ////demo
                //_with2.TotalLoginsAllowed = UtilsShared.GetNumberInt(UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.TotalPeriodAllowed));
                //_with2.NumberOfLogins = UtilsShared.GetNumberInt(UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.NumberOfLogins));
                // _with2.ApplicationsXML = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.ApplicationsXML);


                // _with2.TagMatchingXml = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.TagMatchingXml);
                //_with2.InstallationDemoXML = UtilsShared.GetSettingValueUsingLINQ(y, XMLConstantsShared.InstallationDemoXML);

                return(sharedSets);
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex); return(null);
            }
        }
        }//end AddNode2ISummaryXML

        public static List <int> GetIDsList(XmlDocument iSumXmlDoc, string perform)
        {
            try {
                //convert to XDoc
                XDocument xDoc = XDocument.Parse(iSumXmlDoc.OuterXml);
                //check file is not null
                xDoc = xDoc ?? new XDocument();

                string id2Search = "";

                //select ID according to given parameter
                switch (perform)
                {
                case iTimestamp:
                    // case operations
                    id2Search = iTimestamp;
                    break;

                case iCompanyID:
                    // case operations
                    id2Search = iCompanyID;
                    break;

                case iEmpID:
                    // case operations
                    id2Search = iEmpID;
                    break;

                case iServID:
                    // case operations
                    id2Search = iServID;
                    break;

                case iuserID:
                    // case operations
                    id2Search = iuserID;
                    break;

                case iApptID:
                    // case operations
                    id2Search = iApptID;
                    break;
                    //   default:
                    // Do nothing
                }

                //ie:   get NatureBusiness code
                //  var indElem = from key in xmlDocument.Descendants("ID") where key.Parent.Element("Name").Value == natureOfBus select key.Value;

                //  var items = from key in xDoc.Descendants("Time") where key.ElementsAfterSelf.items[0].Value == "Busy"  select key.Value select key.value;
                var items = from key in xDoc.Descendants(id2Search) select key.Value;

                //convert items to list
                List <string> stringItems = items.ToList();

                //convert to ints
                List <int> intIDs = new List <int>();
                // ... Loop with the foreach string.
                foreach (string idStrg in stringItems)
                {
                    System.Diagnostics.Debug.Print(id2Search + "\t ID: \t" + idStrg);
                    //convert to int and add to list
                    intIDs.Add((int)Utils.GetNumberInt(idStrg));
                }

                return(intIDs);
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);
                return(new List <int>());
            }
        }//end AddNode2ISummaryXML
        }//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
Exemple #9
0
        /// <summary>
        /// Send email notification that an exception has occurred.
        /// </summary>
        /// <param name="ex"></param>
        /// <returns>Details of if exception was successful/unsuccessful</returns>
        /// <remarks></remarks>

        /*public static string SendEmailException(ref Exception ex) {
         *
         *  try {
         *      if (SharedSettings.Settings == null) {
         *          throw new Exception("Shared Settings is empty! this means settings.xml needs to be loaded in the application");
         *      }
         *      dynamic exceptionHand = SharedSettings.Settings;
         *
         *
         *
         *      if (exceptionHand.EmailNotificationsOn) {
         *          //create email message
         *          MailAddress fromAddress = new MailAddress("*****@*****.**", exceptionHand.Client + " " + exceptionHand.ApplicationName + " Exception");
         *
         *          string exceptionRecipient = exceptionHand.ExceptionRecipient;
         *          MailAddress toAddress = new MailAddress(exceptionRecipient, "To PI-e2 Support");
         *
         *
         *          //set email body
         *
         *          string Body = "";
         *          //= "<html><head>Application Exception</head><body>"
         *          Body = Body + "Error on: " + exceptionHand.Client + " " + exceptionHand.ApplicationName + ExceptionHandling.buildErrorMessage(ex);
         *          Body = "\n" + "Dear PI-e2 Supporter,<p></p>Unfortunately an exception has occurred on " + exceptionHand.Client + " " + exceptionHand.ApplicationName + " Please check the client's database exceptions table and read the exception below for details.<p></p>" + Body;
         *          Body = Body + "<p></p>Regards," + "\n" + "<p></p>PI-e2 developers";
         *          //Body = Body & "</body></html>"
         *
         *          string Subject = "Error on " + exceptionHand.Client + " " + exceptionHand.ApplicationName;
         *          //, sent at " & DateTime.Now.ToString()
         *
         *          DeliveryNotificationOptions DeliveryOptions = DeliveryNotificationOptions.OnFailure;
         *          System.Net.Mail.MailPriority Priority = MailPriority.Normal;
         *
         *          string Attachfile = null;
         *          MailAddress bcc = null;
         *          MailAddress CC = null;
         *          SendMail.Send(Body, Subject, DeliveryOptions, Priority, toAddress, fromAddress, Attachfile, bcc, CC);
         *
         *          return "Successfully send email exception";
         *      }
         *      return "Settings mean this is not to send an email!";
         *  }
         * catch (Exception ex) {
         *      //do nothing if there is an exception logging an exception - really bad!
         *      System.Diagnostics.Debug.Print("Error in sending email exception " + "\n" + ex.StackTrace + "\n" + ex.Message); ExceptionHandling.LogException(ref ex);
         *      return "";
         *  }
         * }
         *
         * /// <summary>
         * ///
         * /// </summary>
         * /// <param name="message"></param>
         * /// <returns></returns>
         * /// <remarks></remarks>
         * public static string sendEmailException(ref string message) {
         *  try {
         *      if (SharedSettings.Settings == null) {
         *          throw new Exception("Shared Settings is empty! this means settings.xml needs to be loaded in the application");
         *      }
         *      dynamic exceptionHand = SharedSettings.Settings;
         *
         *      if (exceptionHand.EmailNotificationsOn) {
         *          //create email message
         *          string exceptionRecipient = exceptionHand.ExceptionRecipient;
         *          MailAddress fromAddress = new MailAddress("*****@*****.**", exceptionHand.Client + " " + exceptionHand.ApplicationName + " Exception");
         *          MailAddress toAddress = new MailAddress(exceptionRecipient, "To PI-e2 Support");
         *
         *          //set email body
         *          string Body = message;
         *          string Subject = "Message from " + exceptionHand.Client + " " + exceptionHand.ApplicationName + ", sent at " + DateTime.Now.ToString();
         *
         *
         *          DeliveryNotificationOptions DeliveryOptions = DeliveryNotificationOptions.OnFailure;
         *          System.Net.Mail.MailPriority Priority = MailPriority.Normal;
         *
         *          string Attachfile = null;
         *          MailAddress bcc = null;
         *          MailAddress CC = null;
         *          SendMail.Send(Body, Subject, DeliveryOptions, Priority, toAddress, fromAddress, Attachfile, bcc, CC);
         *
         *
         *          return "Successfully send email exception";
         *      }
         *      return "Settings mean this is not to send an email!";
         *  }
         * catch (Exception ex) {
         *      //do nothing if there is an exception logging an exception - really bad!
         *      System.Diagnostics.Debug.Print("Error in sending email exception " + "\n" + ex3.StackTrace + "\n" + ex.Message);  ExceptionHandling.LogException(ref ex);
         *      return "";
         *  }
         * }*/

        #endregion

        /// <summary>
        /// Log exception to text file.
        /// </summary>
        /// <param name="strData"></param>
        /// <param name="FullPath"></param>
        /// <remarks></remarks>
        //As Boolean
        public static void LogExceptionTextFile(ref string strData, ref string FullPath)
        {
            try {
                // Get a StreamReader class that can be used to read the file
                System.Diagnostics.Debug.Print("LogException 3:");
                StreamWriter objStreamWriter = null;
                objStreamWriter = File.AppendText(FullPath);


                // Append the the end of the string
                // followed by the current date and time
                objStreamWriter.WriteLine("Exception occurred at: " + System.DateTime.Now.ToString()); // + Strings.Chr(13));
                objStreamWriter.WriteLine(strData);
                objStreamWriter.WriteLine("------------------------------------------------------------");

                // Close the stream
                objStreamWriter.Close();
                objStreamWriter = null;
            }
            catch (Exception ex) {
                //error in logging exception - really bad!
                System.Diagnostics.Debug.Print("Error in LogException" + "\n" + ex.StackTrace + "\n" + ex.Message); ExceptionHandling.LogException(ref ex);
                System.Diagnostics.Debug.Print(ex.StackTrace.ToString());
            }
        }
        public static void SaveInstallationToDB2(ref Installation i, ref ApptBLL appt, string selectedStaff1stName, string staffFilePhath, string iSumXMLfileName)
        {
            try {
                //get ----summary installation xml-----
                XmlDocument iXmlDoc = CompanyBLL.GetInstallSummanyXMLDoc((short)i.Company.ID, iSumXMLfileName);
                //------ save End-user --------- only 1 always!?
                int?endUser_ContDetID;
                //check user exists on DB
                //   int userIndex = i.EndUsers.FindIndex(endUser => endUser.aspnetUserID.ToString().Equals(endUserASPUserID.ToString(), StringComparison.Ordinal));
                int endUserIndex = i.EndUsers.Count - 1; //endUser added is always the last one?? use IndexFinder INSTEAD?? 22/7/16
                int?endUser_ID   = EndUserBLL.GetPersonIDByASPuserID(i.EndUsers[endUserIndex].aspnetUserID);

                //only add if it doesnt exist
                if (endUser_ID == null)
                {
                    //save endUser contact details to --- DB ----
                    var _with1 = i.EndUsers[endUserIndex].contactDetail;
                    endUser_ContDetID = ContactDetailsBLL.AddContactDetails(_with1.address, _with1.postCode, _with1.city, _with1.country, _with1.landline, _with1.mobile, _with1.email);
                    //save endUser contact details ID to session
                    _with1.ID = endUser_ContDetID;

                    //save End-user to DB
                    var _with2 = i.EndUsers[endUserIndex];
                    endUser_ID = EndUserBLL.AddEndUser(_with2.title, _with2.firstName, _with2.lastName, endUser_ContDetID, _with2.aspnetUserID);
                    //save endUser ID to ---- session -----
                    _with2.ID = endUser_ID;

                    //save USERID to installation xml summary
                    iXmlDoc = AppSettings.AddChild2ISummaryXML(iSumXMLfileName, AppSettings.iuserID, endUser_ID.ToString());
                    iXmlDoc.Save(iSumXMLfileName);
                }
                appt.endUserID = (int)endUser_ID;

                //------ save appointment ------------
                //save appt to ---- DB ----
                int?newApptID = ApptBLL.AddAppointment(appt.date, appt.time, appt.endUserID, appt.serviceID, appt.provider, appt.notes);
                //save apptID to session
                //source http://stackoverflow.com/questions/1710301/what-is-a-predicate-in-c
                Predicate <ApptBLL> oscarFinder = (ApptBLL p) => { return(p.endUserID == endUser_ID); };
                int apptIndex = i.Appointments.FindLastIndex(oscarFinder);
                i.Appointments[apptIndex].ID = newApptID;

                //save USERID to installation xml summary
                if (newApptID != null || newApptID != 0)
                {
                    iXmlDoc = AppSettings.AddChild2ISummaryXML(iSumXMLfileName, AppSettings.iApptID, newApptID.ToString());
                    iXmlDoc.Save(iSumXMLfileName);
                }

                //------- save staff daily schedule to ---- session ------------
                string minutes = "";
                if (appt.time.Minutes == 0)
                {
                    minutes = "00";
                }
                else
                {
                    minutes = appt.time.Minutes.ToString();
                }
                int timeINT = (int)Utils.GetNumberInt(appt.time.Hours.ToString() + minutes);
                //get staff agenda
                //source: http://stackoverflow.com/questions/1568593/how-to-use-indexof-method-of-listobject
                //ie: list1.FindIndex(x => x==5);  // should return 3, as list1[3] == 5;  // given list1 {3, 4, 6, 5, 7, 8}http://www.dotnetperls.com/list-find
                int empIndex            = i.Employees.FindIndex(employee => employee.firstName.Equals(selectedStaff1stName, StringComparison.Ordinal));
                var curSelStaffCalendar = i.Employees[empIndex].agenda.staffCalendar;

                //add booking --- IMPORTANT --> this updates staff's agenda (as BY REF is used)
                bool addedBooking = AgendaBLL.AddBooking(ref curSelStaffCalendar, (DateTime)appt.date, timeINT);
                //R    if (!addedBooking)
                //R     throw new Exception("<H2>ERROR ADDING BOOKING!</H2>");//throw exc here?it doesnt allow DB save 20/7/16

                //------- save staff daily schedule to ---- DB ------------
                //get xml from staff daySchedule
                XmlDocument staffDayScheXML = DayScheduleXML.CreateXMLFromDaySchedule(i.Employees[empIndex], staffFilePhath, (DateTime)appt.date);
                //add dailySchedule to db
                int?newDailySchedID = DailySchedule.AddDailySchedule(i.Employees[empIndex].agenda.ID, (DateTime)appt.date, staffDayScheXML);
                //add ID back to xml
                DayScheduleXML.Add_ID_2DayScheduleXML(DayScheduleXML.STAFF_DAYSCHEDULEXML_FILENAME, newDailySchedID.ToString());
                //i.DailySchedules.Add(newDailySched);

                //------- SAVE  INSTALLATION XML SUMMARY TO DB  ------------
                int?NumbXmlAdded = CompanyBLL.AddCompanyInstallationSummaryXMLByID((short)i.Company.ID, iXmlDoc);
                //------- SAVE  INSTALLATION XML SUMMARY TO SESSION  ------------
                i.Company.iSummaryXML = iXmlDoc;
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);
            }
        }//end SaveInstallationToDB2
        }//end SaveInstallationToDB2

        public static void SaveInstallationToDB(ref Installation i, string iSumXMLfileName)
        {
            try {
                //  System.Diagnostics.Debug.Print(i.ToString());

                //save CLient contact Details
                var _with1    = i.Company.mainClientContact.contactDetail;
                int?contDetID = ContactDetailsBLL.AddContactDetails(_with1.email);
                _with1.ID = contDetID;

                //save CLient
                var _with2   = i.Company.mainClientContact;
                int?clientID = ClientBLL.AddClient(_with2.title, _with2.firstName, _with2.lastName, (int)contDetID, _with2.aspnetUserID);
                _with2.ID = clientID;

                //save Company address/phone numb
                var _with3        = i.Company.businessAddress;
                int?compContDetID = ContactDetailsBLL.AddContactDetails(null, null, null, null, _with3.landline, null, null);
                _with3.ID = compContDetID;

                //save Company
                var _with4 = i.Company;
                int?compID = CompanyBLL.AddCompany(_with4.domain, _with4.industry, _with4.natureOfBusiness, (int)clientID, (int)compContDetID);
                _with4.ID = compID;

                //save Employees
                int?  tempStaffContDetID, tempStaffID;
                short?tempStaffAgendaID;
                foreach (EmployeeBLL staff in i.Employees)
                {
                    //save staff contact details
                    tempStaffContDetID = ContactDetailsBLL.AddContactDetails(staff.contactDetail.email);
                    //save ID to Installation
                    staff.contactDetail.ID = tempStaffContDetID;
                    //save staff agenda
                    tempStaffAgendaID = AgendaBLL.AddAgenda(false, false);
                    staff.agenda.ID   = tempStaffAgendaID;
                    //save employee
                    tempStaffID = EmployeeBLL.AddEmployee(staff.title, staff.firstName, staff.lastName, (int)tempStaffContDetID, staff.aspnetUserID, null, null, tempStaffAgendaID);
                    staff.ID    = tempStaffID;
                }

                //save services
                int?tempServID;
                foreach (ServicesBLL service in i.Services)
                {
                    //save service
                    tempServID = ServicesBLL.AddService(service.name, service.isCertifReq, service.isInsuranceReq, service.description, service.duration, service.durationUnit, service.price);
                    service.ID = tempServID;
                }

                //save Provide
                //FINK!! FINK18/7//16

                //return i //?? Installation if IDs not added byRef

                //-------  create and save summary installation xml file ------------
                XmlDocument iXmlDoc = AppSettings.GetInstallationSummaryXML(i, iSumXMLfileName);
                iXmlDoc.Save(iSumXMLfileName);
                //save intall XML SUMMARY TO DB AND SESSION
                int?NumbXmlAdded = CompanyBLL.AddCompanyInstallationSummaryXMLByID((short)i.Company.ID, iXmlDoc);
                i.Company.iSummaryXML = iXmlDoc;
            }
            catch (Exception ex) {
                ExceptionHandling.LogException(ref ex);
            }
        }
Exemple #12
0
        }//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
Exemple #13
0
        }//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
Exemple #14
0
        /// <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);
            }
        }
Exemple #15
0
        /// <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);
            }
        }