示例#1
0
        internal static void StartSync()
        {
            string sSource  = null;
            string sLog     = null;
            string sMachine = null;

            sSource  = "Wizard Sync";
            sLog     = "Application";
            sMachine = ".";

            using (SqlConnection con = SQLHelper.GetConnection())
            {
                con.Open();
                SqlTransaction trx = null;
                trx = con.BeginTransaction("ShareHolder");

                try
                {
                    Console.WriteLine(string.Format("[{0}] : Start Sync ShareHolder", DateTime.Now.ToString()));
                    LogFileHelper.logList.Add(string.Format("[{0}] : Start Sync ShareHolder", DateTime.Now.ToString()));

                    DataTable wizardData = GetWizardShareHolder(con, trx);

                    LogFileHelper.logList.Add("Successfully get WizardData");
                    //    DateTime DateNow = System.DateTime.Now;
                    int totalRecord = wizardData.Rows.Count;
                    Console.WriteLine(string.Format("ShareHolder Data Counted : [{0}] ", totalRecord.ToString()));
                    LogFileHelper.logList.Add(string.Format("ShareHolder Data Counted : [{0}] ", totalRecord.ToString()));
                    int count = 0;
                    foreach (System.Data.DataRow row in wizardData.Rows)
                    {
                        count += 1;

                        string FileID = row["FileID"].ToString();
                        Console.WriteLine(string.Format("FileID : [{0}]", FileID.ToString()));
                        LogFileHelper.logList.Add(string.Format("FileID : [{0}]", FileID.ToString()));
                        string ShareHolderName = row["ShareHolderName"].ToString().Trim();
                        double?Percentage      = SyncHelper.ConvertToDouble(row["Percentage"].ToString());
                        int    BumiShare       = 0;
                        if (Convert.ToString(row["BumiShare"]).Trim().Equals("True"))
                        {
                            BumiShare = 1;
                        }
                        Guid?CountryRegionID = GetCountryRegionID(con, trx, Convert.ToString(row["RegionName"]).Trim());
                        Console.WriteLine(string.Format("CountryRegionID : [{0}]", CountryRegionID.ToString()));
                        LogFileHelper.logList.Add(string.Format("CountryRegionID : [{0}]", CountryRegionID.ToString()));
                        Nullable <Guid> AccountID = SyncHelper.GetAccountIDByFileID(FileID);

                        if (AccountID.HasValue)
                        {
                            Console.WriteLine(string.Format("AccountID : [{0}]", AccountID.ToString()));
                            LogFileHelper.logList.Add(string.Format("AccountID : [{0}]", AccountID.ToString()));
                            if (SyncHelper.IsNonMSC(AccountID))
                            {
                                continue;
                            }
                            Nullable <Guid> ShareHolderID = GetShareHolderID(con, trx, AccountID, ShareHolderName);

                            if (ShareHolderID.HasValue)
                            {
                                UpdateShareHolder(con, trx, AccountID, ShareHolderID, ShareHolderName, Percentage, BumiShare, CountryRegionID);
                                Console.WriteLine(string.Format("[{0}] {2}/{3} : Update ShareHolder FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Update ShareHolder FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                            }
                            else
                            {
                                CreateShareHolder(con, trx, AccountID, ShareHolderName, Percentage, BumiShare, CountryRegionID, DateTime.Now);
                                Console.WriteLine(string.Format("[{0}] {2}/{3} : Create ShareHolder FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                                LogFileHelper.logList.Add(string.Format("[{0}] {2}/{3} : Create ShareHolder FileID {1}", DateTime.Now.ToString(), FileID, count, totalRecord));
                            }

                            //Calculation based on Shareholder
                            UpdateAccountJVCategory(con, trx, AccountID, new Guid(SyncHelper.AdminID), SyncHelper.AdminName);
                            Console.WriteLine(string.Format("UpdateAccountJVCategory succeed, AccountID : [{0}]", AccountID.ToString()));
                            LogFileHelper.logList.Add(string.Format("UpdateAccountJVCategory succeed, AccountID : [{0}]", AccountID.ToString()));
                            UpdateAccountBumiClassification(con, trx, AccountID, new Guid(SyncHelper.AdminID), SyncHelper.AdminName);
                            Console.WriteLine(string.Format("UpdateAccountBumiClassification succeed, AccountID : [{0}]", AccountID.ToString()));
                            LogFileHelper.logList.Add(string.Format("UpdateAccountBumiClassification succeed, AccountID : [{0}]", AccountID.ToString()));
                            UpdateAccountClassification(con, trx, AccountID, new Guid(SyncHelper.AdminID), SyncHelper.AdminName);
                            Console.WriteLine(string.Format("UpdateAccountClassification succeed, AccountID : [{0}]", AccountID.ToString()));
                            LogFileHelper.logList.Add(string.Format("UpdateAccountClassification succeed, AccountID : [{0}]", AccountID.ToString()));
                        }
                        else
                        {
                            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));
                        }
                    }

                    trx.Commit();

                    Console.WriteLine(string.Format("[{0}] : End Sync ShareHolder", DateTime.Now.ToString()));
                    LogFileHelper.logList.Add(string.Format("[{0}] : End Sync ShareHolder", DateTime.Now.ToString()));
                }
                catch (Exception ex)
                {
                    trx.Rollback();
                    LogFileHelper.logList.Add("ROLLBACK, ERROR: " + ex.Message);
                }

                con.Close();
            }
        }