Esempio n. 1
0
        protected void btnForward_Click(object sender, EventArgs e)
        {
            if (chbxAutoForwardTo.Checked)
            {
                APApprovalProcessEntity aPApprovalProcessEntity = APRobot.GetApprovalProcessByTypeAndReference(MasterDataConstants.APType.BILL, CMBillID);

                IList <APMemberFeedbackEntity> feedbackList = APRobot.GetAllMemberFeedbacks(aPApprovalProcessEntity.APApprovalProcessID);

                IList <APMemberFeedbackEntity> ordered_list = feedbackList.OrderBy(x => x.SequenceNo).ToList();

                APPanelForwardMemberEntity aPPanelForwardMemberEntity = APRobot.GetAPPanelForwardMemberByID(Int64.Parse(ddlForwardTo.SelectedValue));

                var existsInfo = (from s in ordered_list
                                  where s.EmployeeID.ToString() == aPPanelForwardMemberEntity.EmployeeID.ToString()
                                  select s);

                if (existsInfo != null && existsInfo.Count() > 0)
                {
                    MiscUtil.ShowMessage(lblMessage, "Member Already Exists in the Approval Panel", true);
                    return;
                }

                APMemberFeedbackEntity currentEmployeeInfo = (from r in ordered_list
                                                              where r.EmployeeID.ToString() == MiscUtil.GetCurrentEmployeeByMemberID(CurrentMember).ToString()
                                                              select r).FirstOrDefault();

                if (currentEmployeeInfo != null)
                {
                    ordered_list = (from m in ordered_list
                                    where m.SequenceNo > currentEmployeeInfo.SequenceNo
                                    select m).ToList();



                    APMemberFeedbackEntity aPMemberFeedbackEntity = new APMemberFeedbackEntity();

                    aPMemberFeedbackEntity.APApprovalProcessID      = aPApprovalProcessEntity.APApprovalProcessID;
                    aPMemberFeedbackEntity.DepartmentID             = aPPanelForwardMemberEntity.DepartmentID;
                    aPMemberFeedbackEntity.EmployeeID               = aPPanelForwardMemberEntity.EmployeeID;
                    aPMemberFeedbackEntity.SequenceNo               = currentEmployeeInfo.SequenceNo + 1;
                    aPMemberFeedbackEntity.APFeedbackID             = MasterDataConstants.APFeedback.NOT_YET_REQUESTED;
                    aPMemberFeedbackEntity.FeedbackRequestDate      = DateTime.Now;
                    aPMemberFeedbackEntity.FeedbackLastResponseDate = null;
                    aPMemberFeedbackEntity.FeedbackSubmitDate       = null;
                    aPMemberFeedbackEntity.IsProxyEmployeeEnabled   = false;
                    aPMemberFeedbackEntity.ProxyEmployeeID          = null;

                    Int64 aPMemberFeedbackID = FCCAPMemberFeedback.GetFacadeCreate().Add(aPMemberFeedbackEntity, DatabaseOperationType.Add, TransactionRequired.No);

                    foreach (APMemberFeedbackEntity ent in ordered_list)
                    {
                        String fe = SqlExpressionBuilder.PrepareFilterExpression(APMemberFeedbackEntity.FLD_NAME_APMemberFeedbackID, ent.APMemberFeedbackID.ToString(), SQLMatchType.Equal);
                        ent.SequenceNo += 1;
                        FCCAPMemberFeedback.GetFacadeCreate().Update(ent, fe, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    APRobot.UpdateApprovalProcessFeedback(APMemberFeedbackID, MasterDataConstants.APFeedback.APPROVED, MasterDataConstants.APType.BILL, CMBillID);

                    String remarks = txtRemarks.Text.Trim();

                    if (remarks.IsNullOrEmpty())
                    {
                        remarks = "Approved";
                    }

                    remarks = AddProxyMemberInfo(remarks);

                    APRobot.AddAPMemberFeedbackRemarks(APMemberFeedbackID, remarks);

                    EnableDisableApprovalButtons();

                    MiscUtil.ShowMessage(lblMessage, "You have Approved Successfully", UIConstants.MessageType.GREEN);

                    PrepareInitialView();
                    BindList();
                    RedirectPageToPendingList();
                }
            }

            //Previous Code

            else
            {
                if (ddlRejectTo.Items.Count > 0)
                {
                    APRobot.UpdateMemberFeedbackFeedback(APMemberFeedbackID, MasterDataConstants.APFeedback.FORWARDED);
                    APRobot.UpdateMemberFeedbackLastResponseDate(APMemberFeedbackID, DateTime.Now);

                    String remarks = txtRemarks.Text.Trim();

                    if (remarks.IsNullOrEmpty())
                    {
                        remarks = "Forwarded";
                    }

                    remarks = AddProxyMemberInfo(remarks);

                    Int64 aPMemberFeedbackRemarksID = APRobot.AddAPMemberFeedbackRemarks(APMemberFeedbackID, remarks);

                    Int64 aPPanelForwardMemberID = Int64.Parse(ddlForwardTo.SelectedValue);

                    APPanelForwardMemberEntity aPPanelForwardMemberEntity = APRobot.GetAPPanelForwardMemberByID(aPPanelForwardMemberID);

                    APForwardInfoEntity aPForwardInfoEntity = new APForwardInfoEntity();

                    aPForwardInfoEntity.APMemberFeedbackID        = APMemberFeedbackID;
                    aPForwardInfoEntity.APApprovalProcessID       = APApprovalProcessID;
                    aPForwardInfoEntity.APMemberFeedbackRemarksID = aPMemberFeedbackRemarksID;
                    aPForwardInfoEntity.DepartmentID           = aPPanelForwardMemberEntity.DepartmentID;
                    aPForwardInfoEntity.EmployeeID             = aPPanelForwardMemberEntity.EmployeeID;
                    aPForwardInfoEntity.CommentRequestDate     = DateTime.Now;
                    aPForwardInfoEntity.CommentSubmitDate      = null;
                    aPForwardInfoEntity.APMemberComment        = txtForwardRemarks.Text.Trim();
                    aPForwardInfoEntity.APForwardMemberComment = String.Empty;

                    FCCAPForwardInfo.GetFacadeCreate().Add(aPForwardInfoEntity, DatabaseOperationType.Add, TransactionRequired.No);

                    MiscUtil.ShowMessage(lblMessage, "You have forwarded the thread successfully", UIConstants.MessageType.GREEN);

                    PrepareInitialView();
                    BindList();

                    #region Forwarded Mail

                    String MailBody = String.Empty;
                    String Subject  = String.Empty;

                    StringBuilder sb = new StringBuilder();

                    sb.Append("Dear Sir,");
                    sb.Append("<br/>");
                    sb.Append("This is a auto generated mail from the ERP.");
                    sb.Append("<br/>");
                    sb.Append("A Bill Request is Forwarded Request is waiting for your approval");
                    sb.Append("<br/>");
                    sb.Append("<br/>");
                    sb.Append("-");
                    sb.Append("<br/>");
                    sb.Append("Thanks");
                    sb.Append("<br/>");
                    sb.Append("ERP System");
                    MailBody = sb.ToString();
                    Subject  = "ERP, Bill, Forwarded";
                    MailBody = @"Please note that a Bill is Forwarded.-Thanks ERP System";

                    HREmployeeEntity _hREmployeeEntity = FCCHREmployee.GetFacadeCreate().GetByID(aPForwardInfoEntity.EmployeeID);

                    if (_hREmployeeEntity != null)
                    {
                        String[] sendToMail = new String[] { _hREmployeeEntity.PrimaryEmail };
                        MiscUtil.SendMail(sendToMail, Subject, MailBody);
                    }

                    #endregion


                    //RedirectPageToForwardList();
                }
                else
                {
                    MiscUtil.ShowMessage(lblMessage, "Failed to forward", UIConstants.MessageType.RED);
                }
            }
        }