public void SendMailForCompletedToDo()
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "A to do list was completed.";
            string body = "";

            // MailtTo, nameTo
            int createdBy = Int32.Parse(hdfCreatedById.Value);
            EmployeeGateway  employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByEmployeeId(createdBy);

            mailTo = employeeGateway.GetEMail(createdBy);
            nameTo = employeeGateway.GetFullName(createdBy);

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following to do list was completed. \n";
            body = body + "\n Subject: "+ lblTitleSubjectName.Text;
            body = body + "\n Created By: " + tbxCreatedBy.Text;
            body = body + "\n Creation Date: " + tbxCreationDate.Text;
            body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
            body = body + "\n Unit / Equipment: " + tbxUnit.Text;

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        public void SendMailTeamMember()
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "This proposal is promoted to project.";
            string body = "";

            foreach (ListItem lst in cbxlEmployee.Items)
            {
                int employeeId = int.Parse(lst.Value);

                EmployeeGateway employeesGateway = new EmployeeGateway();
                employeesGateway.LoadForMailsByEmployeeId(employeeId);

                if (employeesGateway.Table.Rows.Count > 0)
                {
                    // Assigned TeamMember
                    mailTo = employeesGateway.GetEMail(employeeId);
                    nameTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId);
                }
            }

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following project was promoted to active state. \n";

            // ... for client and project
            body = body + "\n " + lblTitleClientName.Text;
            body = body + "\n Project: " + lblTitleProjectName.Text;

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        public void SendMailForNewTicket()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "A support ticket was created.";
            string body = "";

            // MailtTo, nameTo
            int createdBy = Int32.Parse(hdfTeamMemberId.Value);
            EmployeeGateway employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByEmployeeId(createdBy);

            mailTo = employeeGateway.GetEMail(createdBy);
            nameTo = employeeGateway.GetFullName(createdBy);

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following support ticket was created. \n";
            body = body + "\n Subject: " + hdfSubject.Value;
            body = body + "\n Comment: " + hdfComments.Value;
            body = body + "\n Created By: " + employeeGateway.GetFullName(createdBy);

            if (hdfDueDate.Value != "")
            {
                DateTime dueDate = DateTime.Parse(hdfDueDate.Value);
                string dueDateText = dueDate.Month.ToString() + "/" + dueDate.Day.ToString() + "/" + dueDate.Year.ToString();
                body = body + "\n Due Date: " + dueDateText;
            }

            int categoryId = Int32.Parse(hdfCategoriesSelected.Value);
            SupportTicketCategoryGateway supportTicketCategoryGateway = new SupportTicketCategoryGateway();
            supportTicketCategoryGateway.LoadByCategoryId(categoryId, companyId);
            body = body + "\n Category: " + supportTicketCategoryGateway.GetName(categoryId);

            //int assignTeamMemberId = Int32.Parse(hdfTeamMemberId.Value);
            //EmployeeGateway employeeGatewayForAssignment = new EmployeeGateway();
            //employeeGatewayForAssignment.LoadByEmployeeId(assignTeamMemberId);

            //body = body + "\n Assigned team member: " + employeeGatewayForAssignment.GetFullName(assignTeamMemberId) + "\n";

            body = body + "\n Assigned team member: Anzovino Dan \n";

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        public void SendMailTeamMember()
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "You have assigned service requests.";
            string body = "";

            if (hdfAssignToTeamMember.Value == "True")
            {
                int employeeId = Int32.Parse(hdfTeamMemberId.Value);

                EmployeeGateway employeesGateway = new EmployeeGateway();
                employeesGateway.LoadForMailsByEmployeeId(employeeId);

                if (employeesGateway.Table.Rows.Count > 0)
                {
                    // Assigned TeamMember
                    mailTo = employeesGateway.GetEMail(employeeId);
                    nameTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId);
                }

                // Mails body
                body = body + "\nHi " + nameTo + ",\n\nThe following service request has been assigned to you. \n";

                body = body + "\n Service Number: " + hdfServiceNumber.Value;
                body = body + "\n Service Description: " + hdfServiceDescription.Value;

                if (hdfDeadlineDate.Value != "")
                {
                    DateTime deadlineDate = DateTime.Parse(hdfDeadlineDate.Value);
                    string deadlineDateText = deadlineDate.Month.ToString() + "/" + deadlineDate.Day.ToString() + "/" + deadlineDate.Year.ToString();
                    body = body + "\n Deadline date: " + deadlineDateText;
                }
                else
                {
                    body = body + "\n Deadline date: ";
                }

                int registeredByLoginId = Convert.ToInt32(Session["loginID"]);
                employeesGateway.LoadByLoginId(registeredByLoginId);
                int registeredByEmployeeId = employeesGateway.GetEmployeIdByLoginId(registeredByLoginId);

                if (employeesGateway.Table.Rows.Count > 0)
                {
                    body = body + "\n Assigned By: " + employeesGateway.GetFirstName(registeredByEmployeeId) + " " + employeesGateway.GetLastName(registeredByEmployeeId);
                }

                //Send Mail
                SendMail(mailTo, subject, body);
            }
        }
        private void UpdateDatabase()
        {
            // Get ids
            int companyId = Int32.Parse(hdfCompanyId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // ... Update general todo list state
                SupportTicketInformationBasicInformation supportTicketInformationBasicInformation = new SupportTicketInformationBasicInformation(supportTicketInformationTDS);
                supportTicketInformationBasicInformation.Save(companyId);

                // ... Save to do list details
                SupportTicketInformationActivityInformation supportTicketInformationActivityInformation = new SupportTicketInformationActivityInformation(supportTicketInformationTDS);
                supportTicketInformationActivityInformation.Save(companyId);

                // ... Send mails
                int createdBy = Int32.Parse(hdfCreatedById.Value);
                string mailTo = "";
                string nameTo = "";

                // ... ... MailtTo, nameTo
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(createdBy);

                mailTo = employeeGateway.GetEMail(createdBy);
                nameTo = employeeGateway.GetFullName(createdBy);

                SupportTicketInformationActivityInformation supportTicketInformationActivityInformationForMails = new SupportTicketInformationActivityInformation(supportTicketInformationTDS);

                foreach (GridViewRow row in grdSupportTicket.Rows)
                {
                    bool sendMail = bool.Parse(((Label)row.FindControl("lblSendMail")).Text);

                    if (sendMail)
                    {
                        string subject = "";
                        string body = "";
                        string comment = "";

                        string type_ = ((Label)row.FindControl("lblType")).Text;
                        switch (type_)
                        {
                            case "AssignUser":
                                // Get mail information
                                subject = "A usser was assigned to the following ticket.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nA usser was assigned to the following ticket. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                string assignedUser = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

                                //Send Mail
                                SendMail(mailTo, subject, body);
                                break;

                            case "AssignToOwner":
                                // Get mail information
                                subject = "The following ticket was assigned to it's owner.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nThe following ticket was assigned to it's owner. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Owner: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                string assignedOwer = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Assigned To Owner: " + assignedOwer;
                                body = body + "\n Due Date: " + tbxDueDate.Text;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

                                //Send Mail
                                SendMail(mailTo, subject, body);
                                break;

                            case "AddComment":
                                // Get mail information
                                subject = "A comment was added to the following ticket.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nA comment was added to the following ticket. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                string commentAddedBy = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Comment added by: " + commentAddedBy;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

                                //Send Mail
                                SendMail(mailTo, subject, body);
                                break;

                            case "CloseTicket":
                                // Get mail information
                                subject = "A support ticket was completed.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nThe following support ticket was completed. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                string completedBy = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Completed by: " + completedBy;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

                                //Send Mail
                                SendMail(mailTo, subject, body);
                                break;

                            case "OnHold":
                                // Get mail information
                                subject = "The following ticket was put on hold.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nThe following ticket was put on hold. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                string onHoldBy = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n On hold by: " + onHoldBy;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

                                //Send Mail
                                SendMail(mailTo, subject, body);
                                break;
                        }
                    }
                }

                DB.CommitTransaction();

                // Store datasets
                supportTicketInformationTDS.AcceptChanges();
                Session["supportTicketInformationTDS"] = supportTicketInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void SendMailEmployee(string newState)
        {
            if (newState == "Rejected")
            {
                // Update grid rows
                foreach (GridViewRow row in grdVacations.Rows)
                {
                    int requestId = Int32.Parse(grdVacations.DataKeys[row.RowIndex].Values["RequestID"].ToString());
                    if (((CheckBox)row.FindControl("cbxSelected")).Checked)
                    {
                        string rejectReason = ((TextBox)row.FindControl("tbxRejectReason")).Text;

                        // Get mail information
                        string mailTo = "";
                        string nameTo = "";
                        string body = "";
                        string subject = "";

                        VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationTDS);

                        int employeeId = vacationsInformationRequestsInformationGateway.GetEmployeeID(requestId);
                        int rejectedById = (int)ViewState["rejected_by_id"];

                        EmployeeGateway employeesGateway = new EmployeeGateway();
                        employeesGateway.LoadByEmployeeId(employeeId);

                        if (employeesGateway.Table.Rows.Count > 0)
                        {
                            // Assigned TeamMember
                            mailTo = employeesGateway.GetEMail(employeeId);
                            nameTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId);
                        }

                        subject = "Vacation request from " + vacationsInformationRequestsInformationGateway.GetStartDate(requestId).ToShortDateString() + " to " + vacationsInformationRequestsInformationGateway.GetEndDate(requestId).ToShortDateString();

                        // Mails body
                        body = body + "\nHi " + nameTo + ",\n\nThe following vacation request has been rejected: \n\n";
                        body = body + "\t - Vacation request from " + vacationsInformationRequestsInformationGateway.GetStartDate(requestId).ToShortDateString() + " to " + vacationsInformationRequestsInformationGateway.GetEndDate(requestId).ToShortDateString() + "\n";
                        body = body + "\t - Detail: " + vacationsInformationRequestsInformationGateway.GetDetails(requestId) + "\n";
                        body = body + "\t - Comment: " + rejectReason;

                        EmployeeGateway employeeRejected = new EmployeeGateway();
                        employeeRejected.LoadByEmployeeId(rejectedById);

                        if (employeeRejected.Table.Rows.Count > 0)
                        {
                            body = body + "\n" + "\t - Rejected by: " + employeeRejected.GetFirstName(rejectedById) + " " + employeeRejected.GetLastName(rejectedById);
                        }

                        //Send Mail
                        SendMail(mailTo, subject, body);
                    }
                }
            }
        }
        private void SendMailTeamMember()
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "You have assigned service requests.";
            string body = "";

            int employeeId = Int32.Parse(ddlPnlAssignAssignToTeamMember.SelectedValue);
            EmployeeGateway employeesGateway = new EmployeeGateway();
            employeesGateway.LoadForMailsByEmployeeId(employeeId);

            if (employeesGateway.Table.Rows.Count > 0)
            {
                // Assigned TeamMember
                mailTo = employeesGateway.GetEMail(employeeId);
                nameTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId);
            }

            int serviceId = Int32.Parse(hdfServiceId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int companyLevel = Int32.Parse(hdfCompanyLevel.Value);

            ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
            serviceInformationBasicInformationGateway.LoadByServiceId(serviceId, companyId);

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following service request has been assigned to you. \n";
            body = body + "\n Unit: " + serviceInformationBasicInformationGateway.GetUnitCode(serviceId) + " - " + serviceInformationBasicInformationGateway.GetUnitDescription(serviceId) + "\n";
            body = body + "\n Fixed Date: ";
            if (serviceInformationBasicInformationGateway.GetMtoDto(serviceId)) body = body + "Yes "; else body = body + "No ";

            string unitType = hdfUnitType.Value;
            if (unitType == "Vehicle")
            {
                body = body + "\n Mileage: " + serviceInformationBasicInformationGateway.GetMileage(serviceId) + " " + hdfMileageUnitOfMeasurement.Value;
            }

            body = body + "\n Problem Description: " + serviceInformationBasicInformationGateway.GetServiceDescription(serviceId);

            if (tkrdpPnlAssignDeadlineDate.SelectedDate.HasValue)
            {
                DateTime deadlineDate = tkrdpPnlAssignDeadlineDate.SelectedDate.Value;
                string deadlineDateText = deadlineDate.Month.ToString() + "/" + deadlineDate.Day.ToString() + "/" + deadlineDate.Year.ToString();
                body = body + " \n Deadline date: " + deadlineDateText;
            }
            else
            {
                body = body + " \n Deadline date: ";
            }

            int registeredByLoginId = Convert.ToInt32(Session["loginID"]);
            employeesGateway.LoadByLoginId(registeredByLoginId);
            int registeredByEmployeeId = employeesGateway.GetEmployeIdByLoginId(registeredByLoginId);
            if (employeesGateway.Table.Rows.Count > 0)
            {
                body = body + "\n Assigned By: " + employeesGateway.GetFirstName(registeredByEmployeeId) + " " + employeesGateway.GetLastName(registeredByEmployeeId);
            }

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        private void SendMailEmployees(DataRow[] drEmployees)
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string body = "";
            string subject = "";

            List<int> employeeIds = new List<int>();
            int lastEmployeeId = 0;
            int lastApprovedById = 0;

            foreach (DataRow row in drEmployees)
            {
                lastEmployeeId = ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).EmployeeID;
                lastApprovedById = ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).ApprovedByID;

                if (!employeeIds.Contains(lastEmployeeId))
                {
                    employeeIds.Add(lastEmployeeId);

                    if (body.Length > 0)
                    {
                        EmployeeGateway employeeApproved = new EmployeeGateway();
                        employeeApproved.LoadByEmployeeId(lastApprovedById);

                        if (employeeApproved.Table.Rows.Count > 0)
                        {
                            body = body + "\n\nApproved by " + employeeApproved.GetFirstName(lastApprovedById) + " " + employeeApproved.GetLastName(lastApprovedById);
                        }

                        //Send Mail
                        SendMail(mailTo, subject, body);

                        mailTo = "";
                        nameTo = "";
                        subject = "";
                        body = "";
                    }

                    EmployeeGateway employeesGateway = new EmployeeGateway();
                    employeesGateway.LoadByEmployeeId(lastEmployeeId);

                    if (employeesGateway.Table.Rows.Count > 0)
                    {
                        // Assigned TeamMember
                        mailTo = employeesGateway.GetEMail(lastEmployeeId);
                        nameTo = employeesGateway.GetFirstName(lastEmployeeId) + " " + employeesGateway.GetLastName(lastEmployeeId);

                        subject = "Project Times Approved";

                        // Mails body
                        body = body + "\nHi " + nameTo + ",\n\nThe followings project time has been approved: \n\n";
                        if (!((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).IsStartTimeNull() && !((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).IsEndTimeNull())
                        {
                            body = body + "\t - Project Time for " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).Date_.ToShortDateString() + ", Start Time: " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).StartTime.ToShortTimeString() + ", End Time: " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).EndTime.ToShortTimeString() + "\n";
                        }
                        else
                        {
                            body = body + "\t - Project Time for " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).Date_.ToShortDateString() + ", " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).WorkingDetails;
                        }
                    }
                }
                else
                {
                    if (!((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).IsStartTimeNull() && !((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).IsEndTimeNull())
                    {
                        body = body + "\t - Project Time for " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).Date_.ToShortDateString() + ", Start Time: " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).StartTime.ToShortTimeString() + ", End Time: " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).EndTime.ToShortTimeString() + "\n";
                    }
                    else
                    {
                        body = body + "\t - Project Time for " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).Date_.ToShortDateString() + ", " + ((ProjectTimeTDS.LFS_PROJECT_TIMERow)row).WorkingDetails;
                    }
                }
            }

            if (body.Length > 0)
            {
                EmployeeGateway employeeApproved = new EmployeeGateway();
                employeeApproved.LoadByEmployeeId(lastApprovedById);

                if (employeeApproved.Table.Rows.Count > 0)
                {
                    body = body + "\n\nApproved by " + employeeApproved.GetFirstName(lastApprovedById) + " " + employeeApproved.GetLastName(lastApprovedById);
                }

                //Send Mail
                SendMail(mailTo, subject, body);

                mailTo = "";
                nameTo = "";
                subject = "";
                body = "";
            }
        }