public void PopulateClientInfo()
        {
            try
            {
                headerGroupMain.ValuesPrimary.Heading = "CLIENT CONTACTS:";
                txtClientInfo.Text = string.Empty;
                TBL_MP_CRM_SalesOrder objOrder = (new ServiceSalesOrder()).GetSalesOrderDBInfoByID(this.SelectedSalesOrderID);
                if (objOrder == null)
                {
                    return;
                }
                SelectedClientID = (int)objOrder.FK_ClientID;

                string strInfo = string.Format("{0} ({1})", objOrder.Tbl_MP_Master_Party.PartyName.ToUpper(), objOrder.Tbl_MP_Master_Party.PartyCode);
                strInfo                       += string.Format("\nemail: {0} Website: {1}", objOrder.Tbl_MP_Master_Party.EmailID, objOrder.Tbl_MP_Master_Party.Website);
                strInfo                       += string.Format("\nGST NO: {0}", objOrder.Tbl_MP_Master_Party.GSTNO);
                txtClientInfo.Text             = strInfo;
                gridCompanyContacts.DataSource = null;
                gridCompanyContacts.DataSource = (new ServiceContacts()).GetMultiSelectListContactsForParty(this.SelectedClientID);
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ControlSalesOrderContacts::PopulateClientInfo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void ScatterData()
        {
            try
            {
                TBL_MP_CRM_SalesOrder model = (new ServiceSalesOrder()).GetSalesOrderDBInfoByID(this.SalesOrderID);
                if (model != null)
                {
                    txtSalesOrderNo.Text             = model.SalesOrderNo;
                    dtSalesOrderDate.Value           = model.SalesOrderDate;
                    cboPOSource.SelectedItem         = ((List <SelectListItem>)cboPOSource.DataSource).Where(x => x.ID == model.FK_POSource).FirstOrDefault();
                    cboSalesOrderStatus.SelectedItem = ((List <SelectListItem>)cboSalesOrderStatus.DataSource).Where(x => x.ID == model.FK_SalesOrderStatus).FirstOrDefault();
                    cboClient.SelectedItem           = ((List <SelectListItem>)cboClient.DataSource).Where(x => x.ID == model.FK_ClientID).FirstOrDefault();

                    if (model.MaterialSupplyPONo != null)
                    {
                        txtMaterialSupplyPoNo.Text = model.MaterialSupplyPONo;
                    }
                    if (model.MaterialSupplyPODate != null)
                    {
                        dtMaterialSupplyPoDate.Value = (DateTime)model.MaterialSupplyPODate;
                    }
                    if (model.MaterialSupplyPOValidDays != null)
                    {
                        txtMaterialSupplyPoValidDays.Text = model.MaterialSupplyPOValidDays.ToString();
                    }
                    if (model.MaterialSupplyPOExpiryDate != null)
                    {
                        dtInstallationServicePoExpiryDate.Value = (DateTime)model.MaterialSupplyPOExpiryDate;
                    }

                    if (model.InstallationServicePONo != null)
                    {
                        txtInstallationServicePoNo.Text = model.InstallationServicePONo;
                    }
                    if (model.InstallationServicePODate != null)
                    {
                        dtInstallationServicePoDate.Value = (DateTime)model.InstallationServicePODate;
                    }
                    if (model.InstallationServicePOValidDays != null)
                    {
                        txtInstallationServicePoValidDays.Text = model.InstallationServicePOValidDays.ToString();
                    }
                    if (model.InstallationServicePOExpiryDate != null)
                    {
                        dtInstallationServicePoExpiryDate.Value = (DateTime)model.InstallationServicePOExpiryDate;
                    }
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmSO_WithoutOrder::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        public ScheduleCallAddEditModel GetSchdeuledCallAddEditModelForSchedule(int scheduleID)
        {
            ScheduleCallAddEditModel model = new ScheduleCallAddEditModel()
            {
                ScheduleID = scheduleID
            };

            try
            {
                TBL_MP_CRM_ScheduleCallLog log = _dbContext.TBL_MP_CRM_ScheduleCallLog.Where(x => x.ScheduleID == model.ScheduleID).FirstOrDefault();
                if (log != null)
                {
                    model.SOURCE_ENTITY    = (APP_ENTITIES)log.EntityType;
                    model.SOURCE_ENTITY_ID = (int)log.EntityID;
                    model.DB_MODEL         = log;
                    model.listAssignees    = this.GelAllAssigneesForSchedule(model.ScheduleID);
                    string strCaption = string.Empty;
                    switch (model.SOURCE_ENTITY)
                    {
                    case APP_ENTITIES.SALES_LEAD:
                        LeadMasterInfoModel leadInfo = (new ServiceSalesLead(_dbContext)).GetLeadMasterInfo(model.SOURCE_ENTITY_ID);
                        strCaption = string.Format("LEAD: {0} {1} dt. {2}", leadInfo.LeadNo, leadInfo.LeadName, leadInfo.LeadDate.Value.ToString("dd MMM yyyy"));
                        break;

                    case APP_ENTITIES.SALES_ENQUIRY:
                        TBL_MP_CRM_SalesEnquiry EnquiryInfo = (new ServiceSalesEnquiry(_dbContext)).GetEnquiryMasterDBInfo(model.SOURCE_ENTITY_ID);
                        strCaption = string.Format("ENQURIY: {0} dt. {1}", EnquiryInfo.SalesEnquiry_No, EnquiryInfo.SalesEnquiry_Date.ToString("dd MMM yyyy"));
                        break;

                    case APP_ENTITIES.SALES_QUOTATION:
                        TBL_MP_CRM_SalesQuotation QuotationInfo = (new ServiceSalesQuotation(_dbContext)).GetSalesQuotationMasterDBInfo(model.SOURCE_ENTITY_ID);
                        strCaption = string.Format("QUOTATION: {0} dt. {1}", QuotationInfo.Quotation_No, QuotationInfo.Quotation_Date.ToString("dd MMM yyyy"));
                        break;

                    case APP_ENTITIES.SALES_ORDER:
                        TBL_MP_CRM_SalesOrder OrderInfo = (new ServiceSalesOrder(_dbContext)).GetSalesOrderDBInfoByID(model.SOURCE_ENTITY_ID);
                        strCaption = string.Format("ORDER: {0} dt. {1}", OrderInfo.SalesOrderNo, OrderInfo.SalesOrderDate.ToString("dd MMM yyyy"));
                        break;
                    }
                    model.HeaderTitle = strCaption;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ServiceScheduleCallLog::GetSchdeuledCallInfo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(model);
        }
Ejemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            TBL_MP_CRM_SalesOrder model   = null;
            ServiceSalesOrder     service = new ServiceSalesOrder();

            try
            {
                errorProvider1.Clear();
                if (!this.ValidateChildren())
                {
                    return;
                }



                if (this.SalesOrderID == 0)
                {
                    model = new TBL_MP_CRM_SalesOrder();
                }
                else
                {
                    model = service.GetSalesOrderDBInfoByID(this.SalesOrderID);
                }

                model.FK_SalesOrderType   = service.SO_TYPE_WITHOUT_ORDER_ID;
                model.SalesOrderNo        = txtSalesOrderNo.Text;
                model.SalesOrderDate      = dtSalesOrderDate.Value;
                model.FK_POSource         = ((SelectListItem)cboPOSource.SelectedItem).ID;
                model.FK_SalesOrderStatus = ((SelectListItem)cboSalesOrderStatus.SelectedItem).ID;
                model.FK_ClientID         = ((SelectListItem)cboClient.SelectedItem).ID;

                if (txtMaterialSupplyPoNo.Text.Trim() != string.Empty)
                {
                    model.MaterialSupplyPONo         = txtMaterialSupplyPoNo.Text.Trim();
                    model.MaterialSupplyPODate       = dtMaterialSupplyPoDate.Value;
                    model.MaterialSupplyPOValidDays  = int.Parse(txtMaterialSupplyPoValidDays.Text.Trim());
                    model.MaterialSupplyPOExpiryDate = dtMaterialSupplyPoExpiryDate.Value;
                }
                else
                {
                    model.MaterialSupplyPONo         = null;
                    model.MaterialSupplyPODate       = null;
                    model.MaterialSupplyPOValidDays  = null;
                    model.MaterialSupplyPOExpiryDate = null;
                }

                if (txtInstallationServicePoNo.Text.Trim() != string.Empty)
                {
                    model.InstallationServicePONo         = txtInstallationServicePoNo.Text.Trim();
                    model.InstallationServicePODate       = dtInstallationServicePoDate.Value;
                    model.InstallationServicePOValidDays  = int.Parse(txtInstallationServicePoValidDays.Text.Trim());
                    model.InstallationServicePOExpiryDate = dtInstallationServicePoExpiryDate.Value;
                }
                else
                {
                    model.InstallationServicePONo         = null;
                    model.InstallationServicePODate       = null;
                    model.InstallationServicePOValidDays  = null;
                    model.InstallationServicePOExpiryDate = null;
                }

                if (this.SalesOrderID == 0)
                {
                    model.CreatedBy    = Program.CURR_USER.EmployeeID;
                    model.CreatedDate  = AppCommon.GetServerDateTime();
                    model.FK_CompanyID = Program.CURR_USER.CompanyID;
                    model.FK_BranchID  = Program.CURR_USER.BranchID;
                    model.FK_YearID    = Program.CURR_USER.FinYearID;
                    this.SalesOrderID  = service.AddNewSalesOrder(model);
                }
                else
                {
                    model.ModifiedBy   = Program.CURR_USER.EmployeeID;
                    model.ModifiedDate = AppCommon.GetServerDateTime();
                    service.UpdateSalesOrder(model);
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmSO_WithoutOrder::txtInstallationServicePoValidDays_TextChanged", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
        public void PrepareForInsert()
        {
            DB_MODEL = new TBL_MP_CRM_ScheduleCallLog();
            string strCaption          = string.Empty;
            string strContactNames     = string.Empty;
            string strContactNumbers   = string.Empty;
            string strContactAddresses = string.Empty;

            try
            {
                switch (this.SOURCE_ENTITY)
                {
                case APP_ENTITIES.SALES_LEAD:
                    LeadMasterInfoModel leadInfo = (new ServiceSalesLead()).GetLeadMasterInfo(this.SOURCE_ENTITY_ID);
                    strCaption            = string.Format("LEAD: {0} {1} dt. {2}", leadInfo.LeadNo, leadInfo.LeadName, leadInfo.LeadDate.Value.ToString("dd MMM yyyy"));
                    DB_MODEL.CustomerName = leadInfo.LeadName;

                    List <SelectContactModel> listContacts = (new ServiceSalesLead()).GetContactsForLeadID(this.SOURCE_ENTITY_ID);
                    DB_MODEL.ContactPerson = string.Empty;
                    foreach (SelectContactModel model in listContacts)
                    {
                        string[] names = model.Description1.Split('\n');
                        DB_MODEL.ContactPerson += names[0] + ", ";
                        DB_MODEL.ContactNumber += model.Description2 + ", ";
                        DB_MODEL.Location      += model.Description1.Replace(names[0], "");
                    }

                    DB_MODEL.ContactPerson = DB_MODEL.ContactPerson.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.ContactNumber = DB_MODEL.ContactNumber.TrimEnd(' ').TrimEnd(',');

                    break;

                case APP_ENTITIES.SALES_ENQUIRY:
                    TBL_MP_CRM_SalesEnquiry dbEnquiry = (new ServiceSalesEnquiry()).GetEnquiryMasterDBInfo(this.SOURCE_ENTITY_ID);
                    strCaption            = string.Format("ENQUIRY: {0} {1} dt. {2}", dbEnquiry.SalesEnquiry_No, dbEnquiry.Project_Name, dbEnquiry.SalesEnquiry_Date.ToString("dd MMM yyyy"));
                    DB_MODEL.CustomerName = dbEnquiry.Tbl_MP_Master_Party.PartyName;
                    List <TBL_MP_CRM_SM_ContactReferences> listEnquiryContacts = (new ServiceSalesEnquiry()).GetAllCompanyContactsForSalesEnquiryDB(this.SOURCE_ENTITY_ID);
                    strContactNames = strContactNumbers = strContactAddresses = string.Empty;
                    foreach (TBL_MP_CRM_SM_ContactReferences refContact in listEnquiryContacts)
                    {
                        strContactNames     += string.Format("{0}\n", refContact.Tbl_MP_Master_PartyContact_Detail.ContactPersoneName);
                        strContactAddresses += string.Format("{0}\n\n", refContact.Tbl_MP_Master_PartyContact_Detail.Address);
                        strContactNumbers   += string.Format("Mobile: {0}  {1}", refContact.Tbl_MP_Master_PartyContact_Detail.MobileNo, refContact.Tbl_MP_Master_PartyContact_Detail.AltMobileNo);
                        strContactNumbers   += string.Format("Tel: {0}  {1}\n", refContact.Tbl_MP_Master_PartyContact_Detail.TelephoneNo, refContact.Tbl_MP_Master_PartyContact_Detail.AltTelephoneNo);
                    }

                    DB_MODEL.ContactPerson = strContactNames.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.ContactNumber = strContactNumbers.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.Location      = strContactAddresses;
                    break;

                case APP_ENTITIES.SALES_QUOTATION:
                    TBL_MP_CRM_SalesQuotation dbQuote = (new ServiceSalesQuotation()).GetSalesQuotationMasterDBInfo(this.SOURCE_ENTITY_ID);
                    strCaption            = string.Format("ENQUIRY: {0} dt. {1}", dbQuote.Quotation_No, dbQuote.Quotation_Date.ToString("dd MMM yyyy"));
                    DB_MODEL.CustomerName = dbQuote.Tbl_MP_Master_Party.PartyName;
                    List <TBL_MP_CRM_SM_ContactReferences> listQuoteContacts = (new ServiceSalesQuotation()).GetAllCompanyContactsForSalesQuotationDB(this.SOURCE_ENTITY_ID);
                    strContactNames = strContactNumbers = strContactAddresses = string.Empty;
                    foreach (TBL_MP_CRM_SM_ContactReferences refContact in listQuoteContacts)
                    {
                        strContactNames     += string.Format("{0}\n", refContact.Tbl_MP_Master_PartyContact_Detail.ContactPersoneName);
                        strContactAddresses += string.Format("{0}\n\n", refContact.Tbl_MP_Master_PartyContact_Detail.Address);
                        strContactNumbers   += string.Format("Mobile: {0}  {1}", refContact.Tbl_MP_Master_PartyContact_Detail.MobileNo, refContact.Tbl_MP_Master_PartyContact_Detail.AltMobileNo);
                        strContactNumbers   += string.Format("Tel: {0}  {1}\n", refContact.Tbl_MP_Master_PartyContact_Detail.TelephoneNo, refContact.Tbl_MP_Master_PartyContact_Detail.AltTelephoneNo);
                    }

                    DB_MODEL.ContactPerson = strContactNames.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.ContactNumber = strContactNumbers.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.Location      = strContactAddresses;
                    break;

                case APP_ENTITIES.SALES_ORDER:
                    TBL_MP_CRM_SalesOrder dbOrder = (new ServiceSalesOrder()).GetSalesOrderDBInfoByID(this.SOURCE_ENTITY_ID);
                    strCaption            = string.Format("ORDER: {0} dt. {1}", dbOrder.SalesOrderNo, dbOrder.SalesOrderDate.ToString("dd MMM yyyy"));
                    DB_MODEL.CustomerName = dbOrder.Tbl_MP_Master_Party.PartyName;
                    List <TBL_MP_CRM_SM_ContactReferences> listOrderContacts = (new ServiceSalesOrder()).GetAllCompanyContactsForSalesOrderDB(this.SOURCE_ENTITY_ID);
                    strContactNames = strContactNumbers = strContactAddresses = string.Empty;
                    foreach (TBL_MP_CRM_SM_ContactReferences refContact in listOrderContacts)
                    {
                        strContactNames     += string.Format("{0}\n", refContact.Tbl_MP_Master_PartyContact_Detail.ContactPersoneName);
                        strContactAddresses += string.Format("{0}\n\n", refContact.Tbl_MP_Master_PartyContact_Detail.Address);
                        strContactNumbers   += string.Format("Mobile: {0}  {1}", refContact.Tbl_MP_Master_PartyContact_Detail.MobileNo, refContact.Tbl_MP_Master_PartyContact_Detail.AltMobileNo);
                        strContactNumbers   += string.Format("Tel: {0}  {1}\n", refContact.Tbl_MP_Master_PartyContact_Detail.TelephoneNo, refContact.Tbl_MP_Master_PartyContact_Detail.AltTelephoneNo);
                    }

                    DB_MODEL.ContactPerson = strContactNames.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.ContactNumber = strContactNumbers.TrimEnd(' ').TrimEnd(',');
                    DB_MODEL.Location      = strContactAddresses;
                    break;
                }

                DateTime currDatetime = AppCommon.GetServerDateTime();
                DB_MODEL.StartAt  = currDatetime;
                DB_MODEL.EndsAt   = currDatetime.AddDays(1);
                DB_MODEL.Reminder = currDatetime.AddHours(-1);
                HeaderTitle       = strCaption;

                BindingList <MultiSelectListItem> allEmployees = AppCommon.ConvertToBindingList <MultiSelectListItem>((new ServiceMASTERS()).GetAllEmployeesMultiSelect());
                this.listAssignees = new BindingList <MultiSelectListItem>();
                MultiSelectListItem emp = allEmployees.Where(x => x.ID == currEmpID).FirstOrDefault();
                if (emp != null)
                {
                    this.listAssignees.Add(emp);
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ScheduleCallAddEditModel::PrepareForInsert", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 6
0
        public void PopulateSalesOrderBOQ()
        {
            MODEL = null;
            tabBOQSheets.Pages.Clear();
            Application.DoEvents();
            try
            {
                // check if to be set readonly
                TBL_MP_CRM_SalesOrder dbOrder = (new ServiceSalesOrder()).GetSalesOrderDBInfoByID(SalesOrderID);
                this.ReadOnly = (dbOrder.FK_BOQRepresentativeID != Program.CURR_USER.EmployeeID);

                headerBOQMenu.Values.Heading = String.Empty;
                MODEL = (new ServiceSalesOrderBOQ()).GetBOQViewModelForOrder(this.SalesOrderID);
                if (MODEL == null)
                {
                    MODEL = (new ServiceSalesOrderBOQ()).GenerateDefaultBOQForSalesOrder(this.SalesOrderID);
                }

                if (MODEL != null)
                {
                    headerBOQMenu.Values.Heading = MODEL.BOQ_NUMBER;
                    // CREATE ALL SHEETS
                    foreach (SalesOrderBOQSheet sheet in MODEL.SHEETS)
                    {
                        KryptonPage pageBOQSheet = new KryptonPage()
                        {
                            Text = sheet.SheetName, Name = string.Format("page{0}", tabBOQSheets.Pages.Count + 1)
                        };
                        ControlSalesOrderBOQSheet _sheetControl = new ControlSalesOrderBOQSheet(sheet);
                        _sheetControl.OnValueChanged += _sheetControl_OnValueChanged;
                        _sheetControl.BOQ_MODEL       = MODEL;
                        pageBOQSheet.Controls.Add(_sheetControl);
                        _sheetControl.Dock = DockStyle.Fill;
                        tabBOQSheets.Pages.Add(pageBOQSheet);
                        _sheetControl.ParentTabPage = pageBOQSheet;
                        _sheetControl.PopulateBOQItemsGrid();
                        _sheetControl.Visible  = true;
                        _sheetControl.ReadOnly = this._ReadOnly;
                        //pageBOQSheet.Show();
                        _sheetControl.SetBOQItemsGridColumnSettings();
                        _sheetControl.SetBOQItemsGridColumnFormatting();
                        pageBOQSheet.Refresh();
                        tabBOQSheets.SelectedPage = pageBOQSheet;
                        Application.DoEvents();
                    }

                    // ADD BOQ SUMMARY TAB
                    pageBOQsummary = new KryptonPage()
                    {
                        Text = "SUMMARY", Name = "tabPageBOQSummary"
                    };
                    _BOQSummaryControl      = new ControlSalesOrderBOQSummary(MODEL);
                    _BOQSummaryControl.Dock = DockStyle.Fill;
                    pageBOQsummary.Controls.Add(_BOQSummaryControl);
                    tabBOQSheets.Pages.Add(pageBOQsummary);
                    _BOQSummaryControl.PopulateBOQSummaryControl();
                    _BOQSummaryControl.ReadOnly = this._ReadOnly;
                }

                // perform grid formatting and column settings again
                foreach (KryptonPage page in tabBOQSheets.Pages)
                {
                    if (page.Controls[0].GetType() == typeof(ControlSalesQuotationBOQSheet))
                    {
                        ControlSalesQuotationBOQSheet sheet = (ControlSalesQuotationBOQSheet)page.Controls[0];
                        sheet.SetBOQItemsGridColumnSettings();
                        sheet.SetBOQItemsGridColumnFormatting();
                    }
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ControlSalesOrderBOQ::PopulateSalesQuotationBOQ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 7
0
        public async Task <int> AddNewScheduleCall(ScheduleCallAddEditModel model, int createdBy)
        {
            string strMessage      = string.Empty;
            string strAssignees    = string.Empty;
            string strRequirements = string.Empty;

            try
            {
                progressForm      = new frmProgress();
                progressForm.Text = "CREATING A NEW SCHEDULE CALL";
                progressForm.lblProgressText.Text = "Inserting a New Business Schecule Call";
                progressForm.Show();
                Application.DoEvents();


                model.DB_MODEL.EntityType      = (int)model.SOURCE_ENTITY;
                model.DB_MODEL.EntityID        = (int)model.SOURCE_ENTITY_ID;
                model.DB_MODEL.CreatedBy       = createdBy;
                model.DB_MODEL.CreatedDatetime = AppCommon.GetServerDateTime();
                model.DB_MODEL.Reminder        = model.DB_MODEL.Reminder;
                model.DB_MODEL.IsDeleted       = false;
                model.DB_MODEL.Completed       = false;
                _dbContext.TBL_MP_CRM_ScheduleCallLog.Add(model.DB_MODEL);
                _dbContext.SaveChanges();
                model.ScheduleID = model.DB_MODEL.ScheduleID;

                progressForm.SetProgress(30, string.Format("\nSuccess ID: {0}\n\nInserting Assignees for this schedule in Database.", model.ScheduleID));
                Application.DoEvents();
                string mailTo = string.Empty;
                foreach (MultiSelectListItem item in model.listAssignees)
                {
                    _dbContext.TBL_MP_CRM_ScheduleCallLogAssignee.Add(new TBL_MP_CRM_ScheduleCallLogAssignee()
                    {
                        EmployeeID = item.ID,
                        IsDeleted  = false,
                        ScheduleID = model.ScheduleID
                    });
                    strAssignees += item.Description.Split('\n')[0] + " , ";
                    _dbContext.SaveChanges();
                    mailTo += ServiceEmployee.GetEmployeeEmailByID(item.ID) + ";";
                }
                strAssignees = strAssignees.TrimEnd(' ').TrimEnd(',');
                mailTo      += "*****@*****.**";
                progressForm.SetProgress(60, string.Format("\nSuccess: {0} Assignee(s) inserted in Database for Schdeule #{1}", model.listAssignees.Count, model.ScheduleID));
                progressForm.SetProgress(60, string.Format("\n\n\nSending Email to {0}", mailTo.Replace(";", "; ")));
                Application.DoEvents();
                ServiceEmail mail       = new ServiceEmail();
                string       strSubject = string.Format("New Schedule Call: {0}", model.DB_MODEL.Subject.ToUpper());

                switch (model.SOURCE_ENTITY)
                {
                case APP_ENTITIES.SALES_LEAD:
                    LeadMasterInfoModel lead = (new ServiceSalesLead(_dbContext)).GetLeadMasterInfo(model.SOURCE_ENTITY_ID);
                    if (lead != null)
                    {
                        strMessage     += String.Format("\n\n\nLead No.: {0} dt. {1}\nParty Name: {2}\n", lead.LeadNo, lead.LeadDate.Value.ToString("dd MMMyy"), lead.LeadName);
                        strRequirements = string.Format("Lead Requirements:\n{0}", lead.LeadRequirement);
                    }
                    break;

                case APP_ENTITIES.SALES_ENQUIRY:
                    TBL_MP_CRM_SalesEnquiry enquiry = (new ServiceSalesEnquiry(_dbContext)).GetEnquiryMasterDBInfo(model.SOURCE_ENTITY_ID);
                    if (enquiry != null)
                    {
                        strMessage += String.Format("\n\n\nEnquiry No.: {0} dt. {1}\nParty Name: {2}\n",
                                                    enquiry.SalesEnquiry_No,
                                                    enquiry.SalesEnquiry_Date.ToString("dd MMMyy"),
                                                    enquiry.Tbl_MP_Master_Party.PartyName);
                        strRequirements = string.Format("Description:\n{0}", enquiry.General_Description);
                    }
                    break;

                case APP_ENTITIES.SALES_QUOTATION:
                    TBL_MP_CRM_SalesQuotation quotation = (new ServiceSalesQuotation(_dbContext)).GetSalesQuotationMasterDBInfo(model.SOURCE_ENTITY_ID);
                    if (quotation != null)
                    {
                        strMessage += String.Format("\n\n\n Quotation No.: {0} dt. {1}\nParty Name: {2}\n",
                                                    quotation.Quotation_No,
                                                    quotation.Quotation_Date.ToString("dd MMMyy"),
                                                    quotation.Tbl_MP_Master_Party.PartyName);
                        strRequirements = string.Format("Special Note:\n{0}", quotation.SpecialNotes);
                    }
                    break;

                case APP_ENTITIES.SALES_ORDER:
                    TBL_MP_CRM_SalesOrder order = (new ServiceSalesOrder(_dbContext)).GetSalesOrderDBInfoByID(model.SOURCE_ENTITY_ID);
                    if (order != null)
                    {
                        strMessage += String.Format("\n\n\n Order No.: {0} dt. {1}\nParty Name: {2}\n",
                                                    order.SalesOrderNo,
                                                    order.SalesOrderDate.ToString("dd MMMyy"),
                                                    order.Tbl_MP_Master_Party.PartyName);
                        strRequirements = string.Empty;
                    }
                    break;
                }
                strMessage += string.Format("\nContact Person(s) : {0}", model.DB_MODEL.ContactPerson);
                strMessage += string.Format("\nContact Number(s) : {0}", model.DB_MODEL.ContactNumber);
                strMessage += string.Format("\nAddress : {0}", model.DB_MODEL.Location);
                strMessage += string.Format("\n\nSCHEDULE\nSchedule Type: {0}", (new ServiceMASTERS(_dbContext)).GetAllScheduleCallActions().Where(x => x.ID == model.DB_MODEL.ActionID).FirstOrDefault().Description);
                strMessage += string.Format("\nSchdeule Date: {0}\nSchedule Time:{1}", model.DB_MODEL.StartAt.Value.ToString("dd MMM yyyy"), model.DB_MODEL.StartAt.Value.ToString("hh:mm tt"));
                strMessage += string.Format("\nPlan/Action: {0}", model.DB_MODEL.Subject.ToUpper());
                strMessage += string.Format("\nRemarks: {0}\n", model.DB_MODEL.Remarks);


                strMessage += string.Format("\nAssigned To : {0}", strAssignees);

                strMessage += string.Format("\n\n{0}", strRequirements);


                string strEmailFrom = ServiceEmployee.GetEmployeeEmailByID(createdBy);
                await mail.SendScheduleCallCreatedEmailNotification(createdBy, strEmailFrom, mailTo, strSubject, strMessage);

                Application.DoEvents();
                progressForm.Close();
                this.IsScuccess = true;
                return(model.ScheduleID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ServiceScheduleCallLog::AddNewScheduleCall", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(model.ScheduleID);
        }
        public void PopulateSalesOrderGeneralInfo()
        {
            this.Cursor = Cursors.WaitCursor;
            ServiceSalesOrder _service = new ServiceSalesOrder();

            try
            {
                //btnApproveSO.Visible = true;
                DoBlanks();
                SelectListItem        selItem = null;
                List <SelectListItem> lst     = _service.GetAllSalesOrderStatuses();

                TBL_MP_CRM_SalesOrder model = (new ServiceSalesOrder()).GetSalesOrderDBInfoByID(SelectedSalesOrderID);
                if (model != null)
                {
                    headerGroupMain.ValuesPrimary.Heading = model.SalesOrderNo;
                    //  lblSOApprovalInfo.Text =model.FK_ApprovedBy.ToString();
                    // lblSOApprovalInfo.StateCommon.Back.Color1 = (model.IsApproved) ? Color.Green : Color.Red;


                    selItem          = lst.Where(x => x.ID == model.FK_SalesOrderStatus).FirstOrDefault();
                    txtSOStatus.Text = selItem.Description;

                    lst              = (new ServiceMASTERS()).GetAllPOSources();
                    selItem          = lst.Where(x => x.ID == model.FK_POSource).FirstOrDefault();
                    txtPOSource.Text = selItem.Description;

                    if (model.MaterialSupplyPONo != null)
                    {
                        txtMaterialSupplyInfo.Text = string.Format("{0} dt. {1}\nfor {2} days till {3}",
                                                                   model.MaterialSupplyPONo,
                                                                   ((DateTime)model.MaterialSupplyPODate).ToString("dd MMM yyyy"),
                                                                   model.MaterialSupplyPOValidDays,
                                                                   ((DateTime)model.MaterialSupplyPOExpiryDate).ToString("dd/MM/yy"));
                    }


                    if (model.InstallationServicePONo != null)
                    {
                        txtInstallationServicesInfo.Text = string.Format("{0} dt. {1}\nfor {2} days till {3}",
                                                                         model.InstallationServicePONo,
                                                                         ((DateTime)model.InstallationServicePODate).ToString("dd MMM yyyy"),
                                                                         model.InstallationServicePOValidDays,
                                                                         ((DateTime)model.InstallationServicePOExpiryDate).ToString("dd/MM/yy"));
                    }
                    if (model.FK_ClientID != null)
                    {
                        txtClientName.Text = String.Format("{0} ({1}) ",
                                                           model.Tbl_MP_Master_Party.PartyName,
                                                           model.Tbl_MP_Master_Party.PartyCode);
                    }
                    if (model.FK_QuotationID != null)
                    {
                        txtQuotationInfo.Text = String.Format("{0} dt. {1} ",
                                                              model.TBL_MP_CRM_SalesQuotation.Quotation_No,
                                                              model.TBL_MP_CRM_SalesQuotation.Quotation_Date.ToString("dd MMM yyyy"));
                    }

                    if (model.FK_ProjectID != null)
                    {
                        headerProject.Values.Heading = "PROJECT: " + model.TBL_MP_PMC_ProjectMaster.ProjectNumber;
                        txtProjectName.Text          = model.TBL_MP_PMC_ProjectMaster.ProjectName;
                        txtStartDate.Text            = model.TBL_MP_PMC_ProjectMaster.StartDate.ToString("dd MMM yyyy");
                        txtEndDate.Text = model.TBL_MP_PMC_ProjectMaster.EndDate.ToString("dd MMM yyyy");
                        ServiceProject serviceProject = new ServiceProject();
                        txtBillingAddress.Text = serviceProject.GetProjectBillingAddress((int)model.FK_ProjectID);
                        txtSiteAddr.Text       = serviceProject.GetProjectSiteAddress((int)model.FK_ProjectID);
                    }

                    if (model.FK_ApprovedBy == null)
                    {
                        lblSOApprovalInfo.Text = "UN-APPROVED";
                        lblSOApprovalInfo.StateCommon.Back.Color1 = Color.Red;
                    }
                    else
                    {
                        lblSOApprovalInfo.Text = string.Format("APPROVED : {0}", ServiceEmployee.GetEmployeeNameByID((int)model.FK_ApprovedBy));
                        lblSOApprovalInfo.StateCommon.Back.Color1 = Color.Green;
                    }

                    if (!ReadOnly)
                    {
                        WhosWhoModel modell = Program.CONTROL_ACCESS.ListControlAccess.Where(x => x.FormID == this.SALES_ORDER_FORM_ID).FirstOrDefault();
                        if (modell != null)
                        {
                            if (modell.CanApprove)
                            {
                                if (model.FK_ApprovedBy == null)
                                {
                                    btnApproveSO.Visible = true;
                                }
                                else
                                {
                                    btnApproveSO.Visible = false;
                                }
                            }
                            else
                            {
                                btnApproveSO.Visible = false;
                            }
                        }
                    }

                    /*
                     * lblSOApprovalInfo.Text = "Unapproved Order";
                     * lblSOApprovalInfo.StateCommon.Back.Color1 = (model.FK_ApprovedBy == null) ? Color.Red : Color.Green;
                     * WhosWhoModel premission = Program.CONTROL_ACCESS.ListControlAccess.Where(x => x.FormID == DB_FORM_IDs.SALES_ORDER).FirstOrDefault();
                     * if (premission != null)
                     * {
                     *   if (premission.CanApprove)
                     *       if (model.FK_ApprovedBy == null)
                     *           btnApproveSO.Visible = true;
                     *       else
                     *       {
                     *           lblSOApprovalInfo.Text = string.Format("Approved: {0}", ServiceEmployee.GetEmployeeNameByID((int)model.FK_ApprovedBy));
                     *           btnApproveSO.Visible = false;
                     *       }
                     *   else
                     *       btnApproveSO.Visible = false;
                     * }
                     */
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(ex.Message, "ControlSalesOrderGeneralInfo::PopulateSalesOrderGeneralInfo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
        }