예제 #1
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;
        }