public static ReturnObject DeleteShift(string current) { masters_shift page_object = new masters_shift(); ReturnObject return_object = new ReturnObject(); DBConnection db_connection = new DBConnection(); JObject current_data = new JObject(); string company_code = string.Empty; string shift_code = string.Empty; string query = string.Empty; int count = 0; if (HttpContext.Current.Session["username"] == null) // checking session expired or not { return_object = page_object.DoLogout(); } else { try { current_data = JObject.Parse(current); company_code = current_data["company_code"].ToString(); shift_code = current_data["shift_code"].ToString(); query = "select count(*) from employeeMaster where Emp_Shift_Detail = '" + shift_code + "' "; count = db_connection.GetRecordCount(query); if (count > 0) { return_object.status = "error"; return_object.return_data = "Employees have been mapped to this shift. Please reassign or delete the employees."; } else { query = "delete from Shift where Shift_Code = '" + shift_code + "' and CompanyCode = '" + company_code + "' "; db_connection.ExecuteQuery_WithOutReturnValue(query); return_object.status = "success"; return_object.return_data = "Shift deleted successfully!"; } } catch (Exception ex) { Logger.LogException(ex, page, "DELETE_SHIFT"); return_object.status = "error"; return_object.return_data = "An error occurred while deleting this Shift. Please try again. If the error persists, please contact Support."; throw; } } return(return_object); }
public static ReturnObject GetShiftData(int page_number, bool is_filter, string filters) { masters_shift page_object = new masters_shift(); DBConnection db_connection = new DBConnection(); DataTable shifts_data_table = new DataTable(); ReturnObject return_object = new ReturnObject(); string employee_id, query, company_code = string.Empty; int start_row = (page_number - 1) * 30; int number_of_record = page_number * 30 + 1; try { employee_id = HttpContext.Current.Session["employee_id"].ToString(); // if employee is logged in then showing only that employee company shift data ( done for royal group client first then implemnted in standard as well ) if (employee_id != "") { query = "select emp_company from employeemaster where emp_code='" + employee_id + "'"; company_code = db_connection.ExecuteQuery_WithReturnValueString(query); query = "select CompanyCode as company_code, CompanyName as company_name, Shift_Code as shift_code, Shift_Desc as shift_desc, Shift_Hours as shift_hours, IsActive from ( select c.CompanyCode, c.CompanyName, s.Shift_Code, s.Shift_Desc, convert(varchar(5), s.MaxOverTime_General) as 'Shift_Hours', IsActive, ROW_NUMBER() OVER (ORDER BY s.Shift_Code) as row from Shift s, CompanyMaster c where c.CompanyCode = s.CompanyCode and c.CompanyCode='" + company_code + "' "; } else { query = "select CompanyCode as company_code, CompanyName as company_name, Shift_Code as shift_code, Shift_Desc as shift_desc, Shift_Hours as shift_hours, IsActive from ( select c.CompanyCode, c.CompanyName, s.Shift_Code, s.Shift_Desc, convert(varchar(5), s.MaxOverTime_General) as 'Shift_Hours', IsActive, ROW_NUMBER() OVER (ORDER BY s.Shift_Code) as row from Shift s, CompanyMaster c where c.CompanyCode = s.CompanyCode"; } if (is_filter) { query = page_object.GetFilterQuery(filters, query); } //query += " ) a where IsActive=1 and row > " + start_row + " and row < " + number_of_record; query += " ) a where row > " + start_row + " and row < " + number_of_record; shifts_data_table = db_connection.ReturnDataTable(query); return_object.status = "success"; return_object.return_data = JsonConvert.SerializeObject(shifts_data_table, Formatting.Indented); } catch (Exception ex) { Logger.LogException(ex, page, "GET_SHIFT_DATA"); return_object.status = "error"; return_object.return_data = "An error occurred while loading Shift data. Please try again. If the error persists, please contact Support."; } finally { page_object.Dispose(); } return(return_object); }