public static void DeleteData(DataTable table, string path) { string sPath = path.Contains("'") ? path.Replace("'", "''") : path; //DataRow[] rows = table.Select(string.Format("filepath = '{0}'", sPath)); DataRow[] rows = (from row in table.AsEnumerable() where row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Deleted && row.Field <string>("filepath") == path select row).ToArray(); List <string> queryList = new List <string>(); foreach (DataRow row in rows) { string owner = row["fileowner"].ToString().Trim(); if (owner == GlobalService.User) { List <string> sharedList = GetSharedList(GlobalService.DbTable, sPath); foreach (string shared in sharedList) { if (shared == "-") { continue; } if (!UserUtil.IsCnMember(shared.Trim()) && !UserUtil.IsVnMember(shared.Trim()) && !UserUtil.IsJpMember(shared.Trim())) { string tableName = "TB_" + AdUtil.GetUserIdByUsername(shared, "kmhk.local"); string sharedText = string.Format("delete from " + tableName + " where r_path = N'{0}'", sPath); queryList.Add(sharedText); } else { string sharedText = string.Format("delete from TB_OUTSIDE_SHARE where o_path = N'{0}'", sPath); queryList.Add(sharedText); } } string ownerText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath); queryList.Add(ownerText); if (File.Exists(path)) { if (GlobalService.User == UserUtil.HrUserName1()) //if (GlobalService.User == "Ling Wai Man(凌慧敏,Velma)") { string directory = @"\\kdthk-dm1\project\IT System\MyCloud Record\" + DateTime.Today.ToString("yyyyMMdd"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = Path.GetFileName(path); File.Copy(path, directory + @"\" + filename); } File.Delete(path); } string delQuery = string.Format("delete from S_OUT_SHARE where o_path = N'{0}'", sPath); DataServiceMes.GetInstance().ExecuteNonQuery(delQuery); } else { string tableName = "TB_" + AdUtil.GetUserIdByUsername(owner, "kmhk.local"); List <string> sharedList = GetSharedList(tableName, sPath); sharedList.Remove(GlobalService.User); string shared = string.Join(";", sharedList.ToArray()); if (shared == "") { shared = "-"; } string ownerText = string.Format("update " + tableName + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath); queryList.Add(ownerText); string sharedText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath); queryList.Add(sharedText); } if (row.RowState != DataRowState.Deleted) { row.Delete(); } } string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string query = string.Format("insert into TB_LOG (log_datetime, log_category, log_path, log_by) values ('{0}', '{1}', N'{2}', N'{3}')", now, "Delete", sPath, GlobalService.User); queryList.Add(query); foreach (string text in queryList) { DataService.GetInstance().ExecuteNonQuery(text); } //QueryUtil.InsertDataToLocalDb(text); }