public static ReturnObject GetHolidayListData(int page_number, bool is_filter, string filters) { masters_holiday_list page_object = new masters_holiday_list(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); DataTable holiday_list_data = new DataTable(); string query = string.Empty; int start_row = (page_number - 1) * 30, number_of_rows = page_number * 30 + 1; try { query = page_object.GetBaseQuery(); if (is_filter) { query = page_object.GetFilterQuery(filters, query); } query += " group by Hg.holgrpcode, hg.holgrpname, hg.companycode) a where row > " + start_row + " and row < " + number_of_rows; holiday_list_data = db_connection.ReturnDataTable(query); return_object.status = "success"; return_object.return_data = JsonConvert.SerializeObject(holiday_list_data, Formatting.Indented); } catch (Exception ex) { Logger.LogException(ex, page, "GET_HOLIDAY_LIST_DATA"); return_object.status = "error"; return_object.return_data = "An error occurred while loading Holiday List data. Please refresh the page and try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } return(return_object); }
public static ReturnObject DeleteHolidayList(string current, string holidays) { masters_holiday_list page_object = new masters_holiday_list(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); JArray holiday_data = new JArray(); JObject current_data = new JObject(); string company_code = string.Empty, holiday_group_code = string.Empty, holiday_name = string.Empty, holiday_code = string.Empty, year = string.Empty, query = string.Empty; int counter = 0, selected_holiday_count = 0, count = 0; try { current_data = JObject.Parse(current); company_code = current_data["company_code"].ToString(); holiday_group_code = current_data["holiday_group_code"].ToString(); year = current_data["year"].ToString(); query = "select count(*) from BranchMaster where HolidayCode='" + holiday_group_code + "'"; if (db_connection.RecordExist(query)) { return_object.status = "error"; return_object.return_data = "This Holiday Group has been mapped to a Branch. Please delete or reassign the Branch."; } else { holiday_data = JArray.Parse(holidays); for (counter = 0; counter < holiday_data.Count; counter++) { holiday_code = holiday_data[counter]["holiday_code"].ToString(); holiday_name = holiday_data[counter]["holiday_name"].ToString(); selected_holiday_count += 1; page_object.UpdateDatabase(holiday_code, holiday_name, company_code, holiday_group_code, "hal", "D", selected_holiday_count); } query = "select count(*) from HolidayMaster where holgrpcode = '" + holiday_group_code + "' "; count = db_connection.GetRecordCount(query); return_object.status = "success"; return_object.return_data = count.ToString(); } } catch (Exception ex) { Logger.LogException(ex, page, "DELETE_HOLIDAY_LIST"); throw; } return(return_object); }
public static ReturnObject SaveHolidayList(string current, string holidays, string mode) { masters_holiday_list page_object = new masters_holiday_list(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); JArray holiday_data = new JArray(); JObject current_data = new JObject(); int selected_holiday_count = 0, count_restricted_holidays = 0, max_days = 0, counter = 0; string company_code = string.Empty, holiday_group_code = string.Empty, holiday_name = string.Empty, holiday_code = string.Empty, year = string.Empty, query = string.Empty; try { current_data = JObject.Parse(current); company_code = current_data["company_code"].ToString(); holiday_group_code = current_data["holiday_group_code"].ToString(); year = current_data["year"].ToString(); if (mode == "U") { query = "delete from Holidaymaster where holgrpcode = '" + holiday_group_code + "' and holyear = '" + year + "' "; db_connection.ExecuteQuery_WithOutReturnValue(query); } count_restricted_holidays = page_object.GetRestrictedHolidayCount(holidays); max_days = page_object.GetMaximumRestrictedDays(holiday_group_code); if (count_restricted_holidays <= max_days) { holiday_data = JArray.Parse(holidays); for (counter = 0; counter < holiday_data.Count; counter++) { holiday_code = holiday_data[counter]["holiday_code"].ToString(); holiday_name = holiday_data[counter]["holiday_name"].ToString(); selected_holiday_count += 1; page_object.UpdateDatabase(holiday_code, holiday_name, company_code, holiday_group_code, "hol", mode, selected_holiday_count); } return_object.status = "success"; return_object.return_data = "Holiday List saved successfully!"; } else { return_object.status = "error"; return_object.return_data = "Additional Restricted days can't be added to this Holiday List"; } } catch (Exception ex) { Logger.LogException(ex, page, "SAVE_HOLIDAY_LIST"); return_object.status = "error"; return_object.return_data = "An error occurred while saving new Holiday List. Please try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } return(return_object); }