public static ReturnObject EditDepartment(string current, string previous) { masters_department page_object = new masters_department(); ReturnObject return_object = new ReturnObject(); string original_department_name = string.Empty; string company_code = string.Empty; string department_code = string.Empty; string department_name = string.Empty; int count = 0; if (HttpContext.Current.Session["username"] == null) // checking session expired or not { return_object = page_object.DoLogout(); } else { try { JObject current_data = JObject.Parse(current); company_code = current_data["company_code"].ToString(); department_code = current_data["department_code"].ToString(); department_name = current_data["department_name"].ToString(); JObject previous_data = JObject.Parse(previous); original_department_name = previous_data["department_name"].ToString(); if (original_department_name != department_name) { count = page_object.CheckDepartmentName(department_name, company_code); if (count > 0) { return_object.status = "error"; return_object.return_data = "Department Name has been taken. Please try again with a different Name"; return(return_object); } } page_object.UpdateDatabase("U", department_code, department_name, company_code); return_object.status = "success"; return_object.return_data = "Department edited successfully!"; } catch (Exception ex) { Logger.LogException(ex, page, "EDIT_DEPARTMENT"); return_object.status = "error"; return_object.return_data = "An error occurred while saving the Department. Please try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } } return(return_object); }
public static ReturnObject DeleteDepartment(string current) { masters_department page_object = new masters_department(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); string query = string.Empty; string company_code = string.Empty; string department_code = string.Empty; string department_name = string.Empty; int count = 0; if (HttpContext.Current.Session["username"] == null) // checking session expired or not { return_object = page_object.DoLogout(); } else { try { JObject current_data = JObject.Parse(current); department_code = current_data["department_code"].ToString(); department_name = current_data["department_name"].ToString(); company_code = current_data["company_code"].ToString(); query = "select count(*) from EmployeeMaster where Emp_Department = '" + department_code + "' and Emp_Status = 1"; count = db_connection.GetRecordCount(query); if (count > 0) { return_object.status = "error"; return_object.return_data = "Please unassign or delete the employees mapped to this Department and try again."; } else { page_object.UpdateDatabase("D", department_code, department_name, company_code); return_object.status = "success"; return_object.return_data = "Department deleted successfully!"; } } catch (Exception Ex) { Logger.LogException(Ex, page, "DELETE_DEPARTMENT"); return_object.status = "error"; return_object.return_data = "An error occurred while deleteing the Department. Please try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } } return(return_object); }
public static ReturnObject DoExport(string filters, bool is_filter) { masters_department page_object = new masters_department(); ReturnObject return_object = new ReturnObject(); DBConnection db_connection = new DBConnection(); DataTable branch_data = new DataTable(); DateTime now = DateTime.Now; int export_limit = Convert.ToInt32(ConfigurationManager.AppSettings["EXPORT_LIMIT"]); string[] column_names = new string[] { }; string query = string.Empty, file_name = string.Empty; if (HttpContext.Current.Session["username"] == null) // checking session expired or not { return_object = page_object.DoLogout(); } else { try { query = page_object.GetBaseQuery(); if (is_filter) { query += page_object.GetFilterQuery(filters, query); } query += " ) a where row > 0 and row < " + export_limit; branch_data = db_connection.ReturnDataTable(query); if (branch_data.Rows.Count > 0) { file_name = page_object.CreateExport(branch_data); return_object.status = "success"; return_object.return_data = file_name; } else { return_object.status = "info"; return_object.return_data = "No data found with the selected filters. Please try again with different filters."; } } catch (Exception ex) { Logger.LogException(ex, page, "GET_DATA_FOR_EXPORT"); return_object.status = "error"; return_object.return_data = "An error occurred while generating your report. Please try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } } return(return_object); }