private void Delete() { for (int x = 0; x < item.Count; x++) { if (MySQLCommands.TestConnection()) { if (mode.Equals("USER")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteUser(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("FILE") || mode.Equals("USERFILE")) { List<MySqlParameter> param = new List<MySqlParameter>(); param.Add(new MySqlParameter("@fid", item.ElementAt(x))); param.Add(new MySqlParameter("@uid", uid)); if (string.IsNullOrWhiteSpace(MySQLCommands.GetValue("select is_protected from tbl_userfiles where FID = @fid and UID = @uid", param))) { //if wla cya access code using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteFile(item.ElementAt(x), uid, permDelete))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else { using (frmFilePassword filePwd = new frmFilePassword(uid, item.ElementAt(x))) { DialogResult result = filePwd.ShowDialog(); if (result == DialogResult.OK) { if (filePwd.correct) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteFile(item.ElementAt(x), uid, permDelete))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteFile(item.ElementAt(x), uid, permDelete))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } } } } } else if (mode.Equals("CLASS")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteClass(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("SUBJECT")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteSubject(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("AREA")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteArea(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("RFC")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.RemoveFromClass(item.ElementAt(x), itemName.ElementAt(x)))) { task.Wait(); processed++; currentItem = item.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("CW")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeletePDF(item.ElementAt(x), permDelete))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("PC")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeletePC(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("ACTFILE")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteActivityFile(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("ACTIVITY")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteActivity(item.ElementAt(x)))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } else if (mode.Equals("MESSAGE")) { using (Task task = Task.Factory.StartNew(() => MySQLCommands.DeleteMessage(item.ElementAt(x),uid))) { task.Wait(); processed++; currentItem = itemName.ElementAt(x); InvokeUpdateControls(); } } } else { XtraMessageBox.Show("Can't connect to the remote server", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } this.Invoke((MethodInvoker)delegate { this.Close(); }); }
private void Download() { for (int x = 0; x < item.Count; x++) { if (MySQLCommands.TestConnection()) { if (mode.Equals("FILE") || mode.Equals("ACTRESPOND")) { List<MySqlParameter> param = new List<MySqlParameter>(); param.Add(new MySqlParameter("@fid", item.ElementAt(x))); param.Add(new MySqlParameter("@uid", ownerUID)); if (string.IsNullOrWhiteSpace(MySQLCommands.GetValue("select is_protected from tbl_userfiles where FID = @fid and UID = @uid", param))) { //if wla cya access code if (File.Exists(dir + "\\" + itemName.ElementAt(x))) { if (XtraMessageBox.Show("The file " + itemName.ElementAt(x) + " already exist in the directory " + dir + " \n Replace File ?", "Duplicate Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question).Equals(DialogResult.Yes)) { //continue,replace the file Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadFile(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } } else { Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadFile(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } } else { using (frmFilePassword filePwd = new frmFilePassword(ownerUID, item.ElementAt(x))) { DialogResult result = filePwd.ShowDialog(); if (result == DialogResult.OK) { if (filePwd.correct) { if (File.Exists(dir + "\\" + itemName.ElementAt(x))) { if (XtraMessageBox.Show("The file " + itemName.ElementAt(x) + " already exist in the directory " + dir + " \n Replace File ?", "Duplicate Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question).Equals(DialogResult.Yes)) { //continue,replace the file Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadFile(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } } else { Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadFile(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } } } } } } else if (mode.Equals("CW")) { if (File.Exists(dir + "\\" + itemName.ElementAt(x))) { if (XtraMessageBox.Show("The file " + itemName.ElementAt(x) + " already exist in the directory " + dir + " \n Replace File ?", "Duplicate Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question).Equals(DialogResult.Yes)) { //continue,replace the file Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadPDF(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } } else { Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadPDF(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } } else if (mode.Equals("VPDF")) { Task task = Task.Factory.StartNew(() => MySQLCommands.DownloadPDF(item.ElementAt(x), itemName.ElementAt(x), dir)); task.Wait(); currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } //BATCH else if (mode.Equals("BATCH")) { for (int y = 0; y < fileNamewExt.Count; y++) { List<MySqlParameter> param = new List<MySqlParameter>(); param.Add(new MySqlParameter("@file", fileNamewExt.ElementAt(y))); param.Add(new MySqlParameter("@UID", item.ElementAt(x))); param.Add(new MySqlParameter("@area", area)); if (string.IsNullOrWhiteSpace(MySQLCommands.GetValue("select is_protected from tbl_userfiles where FID = (SELECT tbl_files.FID FROM tbl_userfiles INNER JOIN tbl_files ON tbl_userfiles.FID = tbl_files.FID INNER JOIN tbl_areafiles ON tbl_areafiles.userfile_id = tbl_userfiles.userfile_id WHERE CONCAT(tbl_files.file_name,tbl_files.file_ext) = @file AND tbl_userfiles.UID = @UID AND tbl_areafiles.area_id = (SELECT tbl_area.area_id FROM tbl_area WHERE tbl_area.area = @area) and tbl_files.status = 1)", param))) { //if access code ang file if (MySQLCommands.DoesExist("SELECT tbl_files.FID FROM tbl_userfiles INNER JOIN tbl_files ON tbl_userfiles.FID = tbl_files.FID INNER JOIN tbl_areafiles ON tbl_areafiles.userfile_id = tbl_userfiles.userfile_id WHERE CONCAT(tbl_files.file_name,tbl_files.file_ext) = @file AND tbl_userfiles.UID = @UID AND tbl_areafiles.area_id = (SELECT tbl_area.area_id FROM tbl_area WHERE tbl_area.area = @area) and tbl_files.status = 1", param)) { string userDir = dir + "\\" + item.ElementAt(x) + " , " + itemName.ElementAt(x); try { if (Directory.Exists(userDir)) { Task task = Task.Factory.StartNew(() => MySQLCommands.BatchDownload(item.ElementAt(x), fileNamewExt.ElementAt(y), userDir,area)); task.Wait(); } else { Directory.CreateDirectory(userDir); Task task = Task.Factory.StartNew(() => MySQLCommands.BatchDownload(item.ElementAt(x), fileNamewExt.ElementAt(y), userDir, area)); task.Wait(); } currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } catch (Exception) { } } } else { using (frmFilePassword filePwd = new frmFilePassword(ownerUID, item.ElementAt(x))) { DialogResult result = filePwd.ShowDialog(); if (result == DialogResult.OK) { if (filePwd.correct) { if (MySQLCommands.DoesExist("SELECT tbl_files.FID FROM tbl_userfiles INNER JOIN tbl_files ON tbl_userfiles.FID = tbl_files.FID INNER JOIN tbl_areafiles ON tbl_areafiles.userfile_id = tbl_userfiles.userfile_id WHERE CONCAT(tbl_files.file_name,tbl_files.file_ext) = @file AND tbl_userfiles.UID = @UID AND tbl_areafiles.area_id = (SELECT tbl_area.area_id FROM tbl_area WHERE tbl_area.area = @area) and tbl_files.status = 1", param)) { string userDir = dir + "\\" + item.ElementAt(x) + " , " + itemName.ElementAt(x); try { if (Directory.Exists(userDir)) { Task task = Task.Factory.StartNew(() => MySQLCommands.BatchDownload(item.ElementAt(x), fileNamewExt.ElementAt(y), userDir, area)); task.Wait(); } else { Directory.CreateDirectory(userDir); Task task = Task.Factory.StartNew(() => MySQLCommands.BatchDownload(item.ElementAt(x), fileNamewExt.ElementAt(y), userDir, area)); task.Wait(); } currentItem = itemName.ElementAt(x); processed++; InvokeUpdateControls(); } catch (Exception) { } } } } } } } } } else { XtraMessageBox.Show("Can't connect to the remote server", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } this.Invoke((MethodInvoker)delegate { this.Close(); }); }