public Main() { InitializeComponent(); try { GlobalService.RootTable = RootUtil.RootDataTable(); receivedCount = MessageUtil.GetReceivedCount(GlobalService.RootTable); tsbtnReceived.Text = "Received" + " (" + receivedCount + ")"; receivedList = MessageUtil.ReceivedList(GlobalService.RootTable); noticeCount = GlobalService.NoticeList.Count; tsbtnNotice.Text = "Notice" + " (" + noticeCount + ")"; approvalCount = MessageUtil.GetApprovalCount(); tsbtnApproval.Text = "Approval" + " (" + approvalCount + ")"; if (SettingUtil.LoadSetting() == "True") { pnlLeft.Width = 200; btnExtend.BackgroundImage = Properties.Resources.left_button_basic_blue; isExtended = true; } else { pnlLeft.Width = 41; btnExtend.BackgroundImage = Properties.Resources.right_button_basic_blue; isExtended = false; } Application.Idle += new EventHandler(Application_Idle); docView = new DocumentView(); //docView.GetFileCountEvent += new EventHandler(docView_GetFileCountEvent); docView.GetNoticeEvent += new EventHandler(docView_GetNoticeEvent); this.LoadControl(docView); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); } }
private void btnSave_Click(object sender, EventArgs e) { string directory = @"\\kdthk-dm1\project\KDTHK-DM\" + AdUtil.getAccount("kmhk.local"); List <string> queryList = new List <string>(); foreach (DataGridViewRow row in dgvCopySetup.Rows) { string fileName = row.Cells[1].Value.ToString(); string keyword = row.Cells[2].Value.ToString(); string favSelection = row.Cells[3].Value.ToString(); string filePath = row.Cells[4].Value.ToString(); string folder = row.Cells[6].Value.ToString(); string shared = row.Cells[7].Value.ToString(); string extension = Path.GetExtension(filePath); string favorite = favSelection == "---" ? "False" : "True"; //if (!Directory.Exists(directory + folder)) // Directory.CreateDirectory(directory + folder); string destination = Path.Combine(directory, fileName + extension); File.Copy(filePath, destination, true); FileInfo info = new FileInfo(destination); FileSecurity fs = info.GetAccessControl(); AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount)); string lastmodified = info.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss"); string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); fs.SetAccessRuleProtection(true, false); fs.AddAccessRule(new FileSystemAccessRule(@"kmhk\itadmin", FileSystemRights.FullControl, AccessControlType.Allow)); fs.AddAccessRule(new FileSystemAccessRule(AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"), FileSystemRights.FullControl, AccessControlType.Allow)); string storedDest = destination; if (storedDest.Contains("'")) { storedDest = storedDest.Replace("'", "''"); } if (fileName.Contains("'")) { fileName = fileName.Replace("'", "''"); } if (keyword.Contains("'")) { keyword = keyword.Replace("'", "''"); } if (shared != "-") { List <string> fileSharedList = shared.Split(';').ToList(); 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 (string item in fileSharedList) { if (UserUtil.IsCnMember(item.Trim())) { cnlist.Add(item.Trim()); } else if (UserUtil.IsVnMember(item.Trim())) { vnlist.Add(item.Trim()); } else if (UserUtil.IsJpMember(item.Trim())) { jplist.Add(item.Trim()); } else { hklist.Add(item.Trim()); } } foreach (string fileShared in hklist) { string sharedId = AdUtil.GetUserIdByUsername(fileShared.Trim(), "kmhk.local"); string tableName = "TB_" + sharedId; fs.AddAccessRule(new FileSystemAccessRule(sharedId, FileSystemRights.Modify, AccessControlType.Allow)); if (UserUtil.IsSpecialUser(fileShared)) //if (fileShared == "Chow Chi To(周志滔,Sammy)" || fileShared == "Ling Wai Man(凌慧敏,Velma)" || fileShared == "Chan Fai Lung(陳輝龍,Onyx)" || fileShared == "Ng Lau Yu, Lilith (吳柳如)" || // fileShared == "Lee Miu Wah(李苗華)" || fileShared == "Lee Ming Fung(李銘峯)" || fileShared == "Ho Kin Hang(何健恒,Ken)" || fileShared == "Yeung Wai, Gabriel (楊偉)") { string asText = string.Format("select as_userid from TB_USER_AS where as_user = N'{0}'", fileShared.Trim()); string asId = DataService.GetInstance().ExecuteScalar(asText).ToString().Trim(); fs.AddAccessRule(new FileSystemAccessRule(asId, FileSystemRights.Modify, AccessControlType.Allow)); } string sharedDivision = SystemUtil.GetDivision(fileShared.Trim()); string sharedDepartment = SystemUtil.GetDepartment(fileShared.Trim()); string sharedVpath = sharedDivision != GlobalService.Division && folder.StartsWith(@"\" + GlobalService.Division) ? @"\Documents" + folder : sharedDepartment != GlobalService.Department && folder.StartsWith(@"\Common") ? @"\Documents" + folder : folder; if (sharedVpath.Contains("'")) { sharedVpath = sharedVpath.Replace("'", "''"); } string sharedText = string.Format("insert into " + tableName + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}')", fileName, extension, keyword, now, lastmodified, GlobalService.User, fileShared.Trim(), storedDest, sharedVpath, "2099/12/31"); queryList.Add(sharedText); } try { File.SetAccessControl(destination, fs); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); continue; } if (cnlist.Count > 0) { PermissionUtil.SetGlobalPermission(cnlist, destination, "kmcn.local"); SharedUtil.SharedCN(cnlist, storedDest, fileName, keyword); } if (vnlist.Count > 0) { PermissionUtil.SetGlobalPermission(vnlist, destination, "kdtvn.local"); SharedUtil.SharedVN(vnlist, storedDest, fileName, keyword); } if (jplist.Count > 0) { PermissionUtil.SetGlobalPermission(jplist, destination, "km.local"); SharedUtil.SharedJp(jplist, storedDest, 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); } } GlobalService.RootTable.Rows.Add(fileName, keyword, lastmodified, now, GlobalService.User, shared, destination, folder, 0, favorite, "True", "False"); if (folder.Contains("'")) { folder = folder.Replace("'", "''"); } if (shared == "") { shared = "-"; } string ownerText = string.Format("insert into " + GlobalService.DbTable + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}')", fileName, extension, keyword, now, lastmodified, GlobalService.User, shared, storedDest, folder, "2099/12/31"); queryList.Add(ownerText); } foreach (string text in queryList) { DataService.GetInstance().ExecuteNonQuery(text); } //DataUtil.SyncDataToServer(); GlobalService.RootTable = RootUtil.RootDataTable(); this.DialogResult = DialogResult.OK; }
private void btnSave_Click(object sender, EventArgs e) { List <string> queryList = new List <string>(); foreach (DataGridViewRow row in dgvShareSetup.Rows) { string name = row.Cells[0].Value.ToString(); string path = row.Cells[1].Value.ToString(); string folder = row.Cells[2].Value.ToString(); string shared = row.Cells[3].Value.ToString(); string keyword = row.Cells[4].Value.ToString(); string modified = row.Cells[5].Value.ToString(); string disc = row.Cells[6].Value.ToString(); string oShared = row.Cells[7].Value.ToString(); string extension = Path.GetExtension(path); string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); if (keyword == "") { keyword = name; } //if (shared == oShared) // continue; FileInfo info = new FileInfo(path); FileSecurity fs = info.GetAccessControl(); AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount)); foreach (FileSystemAccessRule rule in rules) { fs.RemoveAccessRuleSpecific(rule); } fs.SetAccessRuleProtection(true, false); fs.AddAccessRule(new FileSystemAccessRule(@"kmhk\itadmin", FileSystemRights.FullControl, AccessControlType.Allow)); fs.AddAccessRule(new FileSystemAccessRule(AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"), FileSystemRights.FullControl, AccessControlType.Allow)); string sPath = path.Contains("'") ? path.Replace("'", "''") : path; if (DataUtil.IsRecordExists(path)) { List <string> list = DataUtil.GetSharedList(GlobalService.DbTable, path); if (list.Count > 0) { foreach (string item in list) { if (!UserUtil.IsCnMember(item.Trim()) && !UserUtil.IsVnMember(item.Trim()) && !UserUtil.IsJpMember(item.Trim())) { string tbName = "TB_" + AdUtil.GetUserIdByUsername(item.Trim(), "kmhk.local"); string delText = string.Format("delete from " + tbName + " where r_path = N'{0}' and r_owner = N'{1}'", sPath, GlobalService.User); DataService.GetInstance().ExecuteNonQuery(delText); } else { string delText = string.Format("delete from S_OUT_SHARE where o_path = N'{0}' and o_to = N'{1}'", sPath, item.Trim()); DataServiceMes.GetInstance().ExecuteNonQuery(delText); } } } } List <string> sharedList = shared.Split(';').ToList(); 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 (string item in sharedList) { if (UserUtil.IsCnMember(item.Trim())) { cnlist.Add(item.Trim()); } else if (UserUtil.IsVnMember(item.Trim())) { vnlist.Add(item.Trim()); } else if (UserUtil.IsJpMember(item.Trim())) { jplist.Add(item.Trim()); } else { hklist.Add(item.Trim()); } } if (name.Contains("'")) { name = name.Replace("'", "''"); } if (keyword.Contains("'")) { keyword = keyword.Replace("'", "''"); } if (shared != "-") { foreach (string item in hklist) { string sharedId = AdUtil.GetUserIdByUsername(item.Trim(), "kmhk.local"); string tableName = "TB_" + sharedId; string sharedDivision = SystemUtil.GetDivision(item.Trim()); string sharedDepartment = SystemUtil.GetDepartment(item.Trim()); fs.AddAccessRule(new FileSystemAccessRule(sharedId, FileSystemRights.Modify, AccessControlType.Allow)); if (UserUtil.IsSpecialUser(item)) //if (item == "Chow Chi To(周志滔,Sammy)" || item == "Ling Wai Man(凌慧敏,Velma)" || item == "Chan Fai Lung(陳輝龍,Onyx)" || item == "Ng Lau Yu, Lilith (吳柳如)" || // item == "Lee Miu Wah(李苗華)" || item == "Lee Ming Fung(李銘峯)" || item == "Ho Kin Hang(何健恒,Ken)" || item == "Yeung Wai, Gabriel (楊偉)") { string asText = string.Format("select as_userid from TB_USER_AS where as_user = N'{0}'", item.Trim()); string asId = DataService.GetInstance().ExecuteScalar(asText).ToString().Trim(); fs.AddAccessRule(new FileSystemAccessRule(asId, FileSystemRights.Modify, AccessControlType.Allow)); } string sharedVpath = sharedDivision != GlobalService.Division && folder.StartsWith(@"\" + GlobalService.Division) ? @"\Documents" + folder : sharedDepartment != GlobalService.Department && folder.StartsWith(@"\Common") ? @"\Documents" + folder : folder; if (sharedVpath.Contains("'")) { sharedVpath.Replace("'", "''"); } string sharedText = string.Format("insert into " + tableName + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}')", name, extension, keyword, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), modified, GlobalService.User, item.Trim(), sPath, sharedVpath, "2099/12/31"); queryList.Add(sharedText); try { File.SetAccessControl(path, fs); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); continue; } } if (cnlist.Count > 0) { PermissionUtil.SetGlobalPermission(cnlist, path, "kmcn.local"); SharedUtil.SharedCN(cnlist, sPath, name, keyword); } if (vnlist.Count > 0) { PermissionUtil.SetGlobalPermission(vnlist, path, "kdtvn.local"); SharedUtil.SharedVN(vnlist, sPath, name, keyword); } if (jplist.Count > 0) { PermissionUtil.SetGlobalPermission(jplist, path, "km.local"); SharedUtil.SharedJp(jplist, sPath, name, 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); } if (shared == "") { shared = "-"; } string ownerText = string.Format("update " + GlobalService.DbTable + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath); queryList.Add(ownerText); } foreach (string text in queryList) { DataService.GetInstance().ExecuteNonQuery(text); } GlobalService.RootTable = RootUtil.RootDataTable(); this.DialogResult = DialogResult.OK; }
private void btnSave_Click(object sender, EventArgs e) { Debug.WriteLine("btnSave_Click"); try { dgvDocSetup.EndEdit(); List <string> queryList = new List <string>(); foreach (DataGridViewRow row in dgvDocSetup.Rows) { string fileName = row.Cells[0].Value.ToString(); string keyword = row.Cells[1].Value.ToString(); string favSelection = row.Cells[2].Value.ToString(); string selection = row.Cells[3].Value.ToString(); string directory = row.Cells[4].Value.ToString(); string targetDirectory = row.Cells[5].Value.ToString(); string vpath = row.Cells[6].Value.ToString(); string type = row.Cells[7].Value.ToString(); string shared = row.Cells[8].Value.ToString(); string sharedPerson = shared; string favorite = favSelection == "---" ? "False" : "True"; string autoDelete = selection == "7 days" ? DateTime.Today.AddDays(7).ToString("yyyy/MM/dd") : selection == "30 days" ? DateTime.Today.AddDays(30).ToString("yyyy/MM/dd") : selection == "60 days" ? DateTime.Today.AddDays(60).ToString("yyyy/MM/dd") : selection == "90 days" ? DateTime.Today.AddDays(90).ToString("yyyy/MM/dd") : "2099/12/31"; if (keyword == "") { keyword = fileName; } //if (!File.Exists(targetDirectory)) File.Copy(directory, targetDirectory, true); string sPath = targetDirectory; if (sPath.Contains("'")) { sPath = sPath.Replace("'", "''"); } if (DataUtil.IsRecordExists(targetDirectory)) { List <string> list = DataUtil.GetSharedList(GlobalService.DbTable, targetDirectory); if (list.Count > 0) { foreach (string item in list) { string tbName = "TB_" + AdUtil.GetUserId(); string delText = string.Format("delete from " + tbName + " where r_path = N'{0}' and r_owner = N'{1}'", sPath, GlobalService.User); DataService.GetInstance().ExecuteNonQuery(delText); } } string delOwnerText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath); DataService.GetInstance().ExecuteNonQuery(delOwnerText); } FileInfo info = new FileInfo(targetDirectory); FileSecurity fs = info.GetAccessControl(); AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount)); string lastmodified = info.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss"); string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string extension = targetDirectory.Contains(".") ? targetDirectory.Substring(targetDirectory.LastIndexOf("."), targetDirectory.Length - targetDirectory.LastIndexOf(".")) : "file"; foreach (FileSystemAccessRule rule in rules) { fs.RemoveAccessRuleSpecific(rule); } fs.SetAccessRuleProtection(true, false); fs.AddAccessRule(new FileSystemAccessRule(@"kmhk\itadmin", FileSystemRights.FullControl, AccessControlType.Allow)); if (GlobalService.User == "Chow Chi To(周志滔,Sammy)") { fs.AddAccessRule(new FileSystemAccessRule(@"kmas\as1600048", FileSystemRights.FullControl, AccessControlType.Allow)); } if (GlobalService.User == "Ling Wai Man(凌慧敏,Velma)") { fs.AddAccessRule(new FileSystemAccessRule(@"kmas\as1600049", FileSystemRights.FullControl, AccessControlType.Allow)); } if (GlobalService.User == "Ng Lau Yu, Lilith (吳柳如)") { fs.AddAccessRule(new FileSystemAccessRule(@"kmas\as1600051", FileSystemRights.FullControl, AccessControlType.Allow)); } if (GlobalService.User == "Lee Miu Wah(李苗華)") { fs.AddAccessRule(new FileSystemAccessRule(@"kmas\as1600053", FileSystemRights.FullControl, AccessControlType.Allow)); } fs.AddAccessRule(new FileSystemAccessRule(AdUtil.GetUserId(), FileSystemRights.FullControl, AccessControlType.Allow)); List <string> sharedList = new List <string>(); if (fileName.Contains("'")) { fileName = fileName.Replace("'", "''"); } if (keyword.Contains("'")) { keyword = keyword.Replace("'", "''"); } if (shared != "-") { sharedList = shared.Split(';').ToList(); } //foreach (string item in sharedList) // Debug.WriteLine("Item: " + item); 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 (string item in sharedList) { if (UserUtil.IsCnMember(item.Trim())) { cnlist.Add(item.Trim()); } else if (UserUtil.IsVnMember(item.Trim())) { vnlist.Add(item.Trim()); } else if (UserUtil.IsJpMember(item.Trim())) { jplist.Add(item.Trim()); } else { hklist.Add(item.Trim()); } } if (hklist.Count > 0) { foreach (string item in hklist) { string sharedId = AdUtil.GetUserIdByUsername(item.Trim()); string tableName = "TB_" + sharedId; string sharedDivision = SystemUtil.GetDivision(item.Trim()); string sharedDepartment = SystemUtil.GetDepartment(item.Trim()); fs.AddAccessRule(new FileSystemAccessRule(sharedId, FileSystemRights.Modify, AccessControlType.Allow)); if (UserUtil.IsSpecialUser(item)) //if (item == "Chow Chi To(周志滔,Sammy)" || item == "Ling Wai Man(凌慧敏,Velma)" || item == "Chan Fai Lung(陳輝龍,Onyx)" || item == "Ng Lau Yu, Lilith (吳柳如)" || // item == "Lee Miu Wah(李苗華)" || item == "Lee Ming Fung(李銘峯)" || item == "Ho Kin Hang(何健恒,Ken)" || item == "Yeung Wai, Gabriel (楊偉)") { string asText = string.Format("select as_userid from TB_USER_AS where as_user = N'{0}'", item.Trim()); string asId = DataService.GetInstance().ExecuteScalar(asText).ToString().Trim(); fs.AddAccessRule(new FileSystemAccessRule(asId, FileSystemRights.Modify, AccessControlType.Allow)); } string sharedVpath = sharedDivision != GlobalService.Division && vpath.StartsWith(@"\" + GlobalService.Division) ? @"\Documents" + vpath : sharedDepartment != GlobalService.Department && vpath.StartsWith(@"\Common") ? @"\Documents" + vpath : vpath; if (sharedVpath.Contains("'")) { sharedVpath = sharedVpath.Replace("'", "''"); } string sharedText = string.Format("insert into " + tableName + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}')", fileName, extension, keyword, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), lastmodified, GlobalService.User, item.Trim(), sPath, sharedVpath, "2099/12/31"); queryList.Add(sharedText); } } if (targetDirectory.StartsWith(@"\\kdthk-dm1\project\KDTHK-DM")) { File.SetAccessControl(targetDirectory, fs); } else { if (!targetDirectory.StartsWith(@"L:\") && !targetDirectory.StartsWith(@"M:\") && !targetDirectory.StartsWith(@"\\kdthk-dm1\project") && !targetDirectory.StartsWith(@"\\kdthk-dm1")) { File.SetAccessControl(targetDirectory, fs); } } /* Commented out by Cato Yeung */ if (cnlist.Count > 0) { PermissionUtil.SetGlobalPermission(cnlist, targetDirectory, "kmcn.local"); SharedUtil.SharedCN(cnlist, sPath, fileName, keyword); } if (vnlist.Count > 0) { PermissionUtil.SetGlobalPermission(vnlist, targetDirectory, "kdtvn.local"); SharedUtil.SharedVN(vnlist, sPath, fileName, keyword); } if (jplist.Count > 0) { PermissionUtil.SetGlobalPermission(jplist, targetDirectory, "km.local"); SharedUtil.SharedJp(jplist, sPath, fileName, keyword); } try { List <string> receiverlist = cnlist.Concat(vnlist).Concat(jplist).ToList(); //receiverlist.Add(GlobalService.User); if (receiverlist.Count > 0) { EmailUtil.SendNotificationEmail(receiverlist); } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); } //SharedUtil.SharedGlobal(cnList, sPath, fileName, keyword); /*sharedList = sharedList.Distinct().ToList(); * * if (sharedList.Count > 0) * sharedPerson = string.Join(";", sharedList.ToArray());*/ if (vpath.Contains("'")) { vpath = vpath.Replace("'", "''"); } GlobalService.RootTable.Rows.Add(fileName, keyword, lastmodified, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), GlobalService.User, shared, targetDirectory, vpath, 0, favorite, "False"); string ownerText = string.Format("insert into " + GlobalService.DbTable + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}')", fileName, extension, keyword, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), lastmodified, GlobalService.User, shared, sPath, vpath, autoDelete); queryList.Add(ownerText); if (directory.StartsWith(Environment.SpecialFolder.Desktop + @"\MyCloud Sync")) { File.Delete(directory); } } queryList = queryList.Distinct().ToList(); foreach (string text in queryList) { DataService.GetInstance().ExecuteNonQuery(text); } //DataUtil.SyncDataToServer(); GlobalService.RootTable = RootUtil.RootDataTable(); this.DialogResult = DialogResult.OK; } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); MessageBox.Show(ex.Message + ex.StackTrace); } }