Esempio n. 1
0
        public static bool IsNonMSC(Guid AccountID)
        {
            Nullable <Guid> NonMSCAccountTypeCID = SyncHelper.GetCodeMasterID("Non MSC", BOL.AppConst.CodeType.AccountType);

            if (NonMSCAccountTypeCID.HasValue)
            {
                Guid accountTypeCID = GetAccountTypeCID(AccountID);
                return(accountTypeCID == NonMSCAccountTypeCID.Value);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        internal void StartSync()
        {
            LogFileHelper.logList = new ArrayList();
            Console.WriteLine(string.Format("[{0}] : Start Sync Approval Letter", DateTime.Now.ToString()));
            LogFileHelper.logList.Add(string.Format("[{0}] : Start Sync Approval Letter", DateTime.Now.ToString()));
            RecordsCount SyncCount = default(RecordsCount);

            // Initialising the variables
            SyncCount.InsertCount    = 0;
            SyncCount.NoAccountCount = 0;
            SyncCount.NonMSCCount    = 0;
            SyncCount.SameDateCount  = 0;
            SyncCount.UpdateCount    = 0;
            string FileID = "";

            try
            {
                //System.Data.DataTable wizardData = this.GetWizardApprovedDate();
                //UPDATED 10062016
                DataTable wizardData = this.GetFromWizardApprovedDate();
                //statusdate
                //string Filename0 = getFileName();
                //DataTable wizardData = GetWizardApprovedDateFromExcelFile(Filename0, "ApprovalDates_10062016");
                int totalRecord = wizardData.Rows.Count;
                Console.WriteLine(string.Format("[{0}] : Total record for Approval Letter Dates is {1}", DateTime.Now.ToString(), totalRecord));
                LogFileHelper.logList.Add(string.Format("[{0}] : Total record for Approval Letter Dates is {1}", DateTime.Now.ToString(), totalRecord));
                int count = 0;
                //if (totalRecord > 0)
                //{
                //    ExcelFileHelper.GenerateExcelFileApprovalDates(wizardData, DateTime.Now.ToString("dd-MM-yyyy"));
                //}
                Guid?MOFApprovalStatus    = SyncHelper.GetCodeMasterID("Approval Letter", CodeType.MSCApprovalStatus, true);
                Guid MOFApprovalStatusCID = new Guid(MOFApprovalStatus.Value.ToString());
                foreach (System.Data.DataRow row in wizardData.Rows)
                {
                    count += 1;

                    FileID = row["RefNumber"].ToString();
                    FileID = "CS/3/" + FileID;
                    // Field below must be change ****************************************
                    string ApprovalLetterDate = SyncHelper.ConvertStringToDateTime(row["StatusDate"].ToString().Trim(), false).ToString();
                    //Dim StatusDescription As String = SyncHelper.GetMappingValue(AppConst.CodeType.MSCApprovalStatus, "MOF Approved")
                    if (!string.IsNullOrEmpty(ApprovalLetterDate))
                    {
                        Guid?accountID = GetAccountIDByFileID(FileID);

                        if (accountID != null)
                        {
                            if (IsNonMSC(accountID.Value))
                            {
                                SyncCount.NonMSCCount += 1;
                                Console.WriteLine(string.Format("[{0}] {2}/{3} : Skip Non MSC record FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Skip Non MSC record FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                continue;
                            }

                            Guid?MSCStatusHistoryID = GetMSCStatusHistoryID(accountID.Value, MOFApprovalStatusCID);

                            if (MSCStatusHistoryID != null)
                            {
                                if (IsDifferentApprovalDate(MSCStatusHistoryID, ApprovalLetterDate))
                                {
                                    UpdateApprovalLetterDate(accountID.Value, MSCStatusHistoryID.Value, Convert.ToDateTime(ApprovalLetterDate));
                                    SyncCount.UpdateCount += 1;
                                    Console.WriteLine(string.Format("[{0}] {2}/{3} : Update MSCStatusHistory FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                    LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Update MSCStatusHistory FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                }
                                else
                                {
                                    SyncCount.SameDateCount += 1;
                                    Console.WriteLine(string.Format("[{0}] {2}/{3} : Skip same approval letter date FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                    LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Skip same approval letter date FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));                            // Skip to update same date
                                }
                            }
                            else
                            {
                                SyncCount.InsertCount += 1;
                                CreateApprovalLetterDate(accountID.Value, MOFApprovalStatusCID, Convert.ToDateTime(ApprovalLetterDate));
                                Console.WriteLine(string.Format("[{0}] {2}/{3} : Create MSCStatusHistory FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Create MSCStatusHistory FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                            }
                        }
                        else
                        {
                            SyncCount.NonMSCCount += 1;
                            Console.WriteLine(string.Format("[{0}] {2}/{3} : Record FileID {1} not found", DateTime.Now.ToString(), FileID, count, totalRecord));
                            LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Record FileID {1} not found", DateTime.Now.ToString(), FileID, count, totalRecord));
                        }
                    }
                    Console.WriteLine(string.Format("[{0}] : End Sync Approval Letter", DateTime.Now.ToString()));
                    LogFileHelper.logList.Add(string.Format("[{0}] : End Sync Approval Letter", DateTime.Now.ToString()));
                }
            }
            catch (Exception ex)
            {
                LogFileHelper.logList.Add("Error for MSCFileID" + FileID + ", Error : " + ex.Message);
                List <string> TOs = new List <string>();
                //TOs.AddRange(BOL.Common.Modules.Parameter.WIZARD_RCPNT.Split(','));
                TOs.Add("*****@*****.**");
                bool SendSuccess = BOL.Utils.Email.SendMail(TOs.ToArray(), null, null, BOL.Common.Modules.Parameter.WIZARD_SUBJ, string.Format("{0} SyncApprovalLetterDates {1}", BOL.Common.Modules.Parameter.WIZARD_DESC, ex.Message), null);
            }
            //if (LogFileHelper.logList.Count > 0)
            //{
            //    string ModeSync = "ApprovalLetterDatesSyncLog_";
            //    LogFileHelper.WriteLog(LogFileHelper.logList, ModeSync);
            //}
        }