Пример #1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                SetProgressBar(60);

                SetLabel("Initializing components");

                //this.LoadUserAppData();

                SetProgressBar(100);

                SetLabel("Getting user information");

                //GlobalService.User = "******";
                //GlobalService.DbTable = "TB_hk950097";

                /*if (domain == "kmhk.local")
                 *  GlobalService.DbTable = "TB_" + AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local");
                 * else
                 * {
                 *  string id = AdUtil.GetUserIdByUsername(GlobalService.User, domain);
                 *
                 *  string tb = id == "as1600048" ? "hk070022"
                 *      : id == "as1600049" ? "hk110017"
                 *      : id == "as1600050" ? "hk040015"
                 *      : id == "as1600051" ? "hk160002"
                 *      : id == "as1600053" ? "hk950330"
                 *      : id == "as1600054" ? "hk110023"
                 *      : id == "as1600055" ? "hk120027"
                 *      : id == "as1600056" ? "hk140005" : "";
                 *
                 *  GlobalService.DbTable = "TB_" + tb;
                 *
                 *  string name = id == "as1600048" ? "Chow Chi To(周志滔,Sammy)"
                 *      : id == "as1600049" ? "Ling Wai Man(凌慧敏,Velma)"
                 *      : id == "as1600050" ? "Chan Fai Lung(陳輝龍,Onyx)"
                 *      : id == "as1600051" ? "Ng Lau Yu, Lilith (吳柳如)"
                 *      : id == "as1600053" ? "Lee Miu Wah(李苗華)"
                 *      : id == "as1600054" ? "Lee Ming Fung(李銘峯)"
                 *      : id == "as1600055" ? "Ho Kin Hang(何健恒,Ken)"
                 *      : id == "as1600056" ? "Yeung Wai, Gabriel (楊偉)" : "";
                 *
                 *  GlobalService.User = name;
                 * }*/

                //List<string> list = new List<string>();
                //list.Add(GlobalService.User);
                //EmailUtil.SendNotificationEmail(list);

                GlobalService.User = GlobalService.User.Trim();

                try
                {
                    SetLabel("Synchronizing data");

                    SharedUtil.AutoDeleteData();

                    Stopwatch sw = new Stopwatch();

                    sw.Start();
                    GlobalService.DepartmentFolder = SetupUtil.GetDepartmentFolder(GlobalService.User);
                    sw.Stop();
                    Debug.WriteLine("Get Department Folder: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.DivisionMemberList = SystemUtil.DivisionMember(GlobalService.User);
                    sw.Stop();
                    Debug.WriteLine("Get Division Memeber: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.DepartmentMemberList = SystemUtil.DepartmentMember(GlobalService.User);
                    sw.Stop();
                    Debug.WriteLine("Get Department Member: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.SystemGroupList = GroupUtil.SystemGroupList();
                    GlobalService.CNGroupList     = GroupUtil.CnGroupList();
                    GlobalService.VNGroupList     = GroupUtil.VnGroupList();
                    GlobalService.JPGroupList     = GroupUtil.JpGroupList();
                    sw.Stop();
                    Debug.WriteLine("Get System Group: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.CustomGroupList = GroupUtil.CustomGroupList2(GlobalService.User);
                    sw.Stop();
                    Debug.WriteLine("Get Custom Group: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.AllUserList = UserUtil.AllUserList();
                    GlobalService.CnUserList  = UserUtil.CnUserList();
                    GlobalService.VnUserList  = UserUtil.VnUserList();
                    GlobalService.JpUserList  = UserUtil.JpUserList();
                    sw.Stop();
                    Debug.WriteLine("Get All User: "******"Initialize attachment list: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.ExtraSystemGroupList = GroupUtil.ExtraSystemGroupList();
                    sw.Stop();
                    Debug.WriteLine("Get Extra System Group: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.NoticeList = MessageUtil.GetNoticeList();
                    sw.Stop();
                    Debug.WriteLine("Get Notice list: " + sw.Elapsed);

                    GlobalService.IsPasswordInput = false;

                    sw.Reset();
                    sw.Start();
                    GlobalService.DiscList = DiscUtil.PopulateDiscList();
                    sw.Stop();
                    Debug.WriteLine("Populate Disc List: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.Division = SystemUtil.GetDivision(GlobalService.User);
                    sw.Stop();
                    Debug.WriteLine("Get Division: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.AppsList = SystemUtil.AppsList();
                    sw.Stop();
                    Debug.WriteLine("Get Application list: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.DocumentList = new List <lists.DocumentList>();
                    sw.Stop();
                    Debug.WriteLine("Initialize Document List: " + sw.Elapsed);

                    sw.Reset();
                    sw.Start();
                    GlobalService.ContactList = ContactUtil.ContactList();
                    sw.Stop();
                    Debug.WriteLine("Load Contact List: " + sw.Elapsed);

                    GetSystemVersion();

                    UpdateCommon();

                    SharedUtil.UpdateEmptyShared();

                    SharedUtil.UpdateShared();

                    Login();

                    //DataUtil.SyncDataToServer();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                }
            }
            catch (ArgumentException ex)
            {
                File.WriteAllText(@"D:\Error.txt", ex.Message + ex.StackTrace);
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Пример #2
0
        private void SaveData()
        {
            SharedUtil.UpdateEmptyShared();
            SharedUtil.UpdateShared();

            string sPath = _filePath.Contains("'") ? _filePath.Replace("'", "''") : _filePath;

            DataRow[] rows = GlobalService.RootTable.Select(string.Format("filepath = '{0}'", sPath));

            List <string> hklist = new List <string>();
            List <string> cnlist = new List <string>();
            List <string> vnlist = new List <string>();
            List <string> jplist = new List <string>();

            foreach (DataGridViewRow row in dgvUser.Rows)
            {
                string loc = row.Cells[1].Value.ToString().Trim();
                if (loc == "HK")
                {
                    hklist.Add(row.Cells[0].Value.ToString().Trim());
                }
                else if (loc == "CN")
                {
                    cnlist.Add(row.Cells[0].Value.ToString().Trim());
                }
                else if (loc == "VN")
                {
                    vnlist.Add(row.Cells[0].Value.ToString().Trim());
                }
                else
                {
                    jplist.Add(row.Cells[0].Value.ToString().Trim());
                }
            }

            //FileInfo info = new FileInfo(_filePath);
            //FileSecurity fs = info.GetAccessControl();
            //AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount));

            if (deleteList.Count > 0)
            {
                PermissionUtil.RemovePermission(deleteList, _filePath);
            }

            if (deleteCnList.Count > 0)
            {
                PermissionUtil.RemoveGlobalPermission(deleteCnList, _filePath, "kmcn.local");
            }

            if (deleteVnList.Count > 0)
            {
                PermissionUtil.RemoveGlobalPermission(deleteVnList, _filePath, "kdtvn.local");
            }

            if (deleteJpList.Count > 0)
            {
                PermissionUtil.RemoveGlobalPermission(deleteJpList, _filePath, "km.local");
            }

            if (hklist.Count > 0)
            {
                PermissionUtil.SetPermission(hklist, _filePath);
            }

            if (cnlist.Count > 0)
            {
                PermissionUtil.SetGlobalPermission(cnlist, _filePath, "kmcn.local");
            }

            if (vnlist.Count > 0)
            {
                PermissionUtil.SetGlobalPermission(vnlist, _filePath, "kdtvn.local");
            }

            if (jplist.Count > 0)
            {
                PermissionUtil.SetGlobalPermission(jplist, _filePath, "km.local");
            }

            List <string> totalList = hklist.Concat(cnlist).Concat(vnlist).Concat(jplist).ToList();

            string shared = totalList.Count == 0 ? "-" : string.Join(";", totalList.ToArray());

            foreach (DataRow row in rows)
            {
                if (shared == "")
                {
                    shared = "-";
                }

                row["shared"] = shared;

                string text = string.Format("update " + GlobalService.DbTable + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath);
                DataService.GetInstance().ExecuteNonQuery(text);
            }

            string disc = DiscUtil.IsDisc(GlobalService.RootTable, _filePath) ? "True" : "False";

            string extension = Path.GetExtension(_filePath);

            if (_fileName.Contains("'"))
            {
                _fileName = _fileName.Replace("'", "''");
            }

            if (_keyword.Contains("'"))
            {
                _keyword = _keyword.Replace("'", "''");
            }

            foreach (string sharedPerson in hklist)
            {
                string tableName = "TB_" + AdUtil.GetUserIdByUsername(sharedPerson.Trim(), "kmhk.local");

                string sharedDivision   = SystemUtil.GetDivision(sharedPerson.Trim());
                string sharedDepartment = SystemUtil.GetDepartment(sharedPerson.Trim());

                string sharedVpath = sharedDivision != GlobalService.Division && _vpath.StartsWith(@"\" + GlobalService.Division) ? @"\Documents" + _vpath
                            : sharedDepartment != GlobalService.DepartmentFolder && _vpath.StartsWith(@"\Common") ? @"\Documents" + _vpath : _vpath;

                string sharedText = string.Format("if not exists (select * from " + tableName + " where r_path = N'{7}') insert into " + tableName + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate, r_disc)" +
                                                  " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}', '{10}')", _fileName, extension, _keyword, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), _lastModified, GlobalService.User,
                                                  sharedPerson.Trim(), sPath, sharedVpath, "2099/12/31", disc);

                DataService.GetInstance().ExecuteNonQuery(sharedText);
            }

            SharedUtil.SharedCN(cnlist, sPath, _fileName, _keyword);
            SharedUtil.SharedVN(vnlist, sPath, _fileName, _keyword);
            SharedUtil.SharedJp(jplist, sPath, _fileName, _keyword);

            try
            {
                List <string> receiverlist = cnlist.Concat(vnlist).Concat(jplist).ToList();
                if (receiverlist.Count > 0)
                {
                    EmailUtil.SendNotificationEmail(receiverlist);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }

            DialogResult = DialogResult.OK;
        }