using System; using CoreSavingLibrary; using System.Collections.Generic; using System.Linq; using System.Web; using System.Globalization; using System.Data; using DataLibrary; namespace CoreSavingLibrary { public class MenuApplications { public String TrStart { get; set; } public String TrEnd { get; set; } public String WorkDate { get; set; } public String PageLink { get; set; } public String Picture { get; set; } public String PictureCss { get; set; } public String Name { get; set; } public String Application { get; set; } public string AppEvent { get; set; } public string AppLableCss { get; set; } public string WorkDateLableCss { get; set; } public List GetMenuApplication(Sta oracleTA, String coopControl, String username) { CultureInfo th = new CultureInfo("th-TH"); List menu = new List(); int rows = 0; DataTable dt = null; try { string realcoop_control = coopControl; String sql = @"select * from cmcoopmaster where coop_id = {0} "; sql = WebUtil.SQLFormat(sql, coopControl); dt = oracleTA.QueryDataTable(sql); rows = dt.Rows.Count; //ตรวจสอบว่า coop_id ที่ส่งมาเป็นสำนักงานใหญ่หรือไม่ string sql_ext = ""; if (dt.Rows[0]["coop_control"].ToString() == coopControl) { sql_ext = " coop_id = a.coop_id "; } else { sql_ext = " coop_id in (select coop_id from cmcoopmaster where coop_control= '" + dt.Rows[0]["coop_control"] + "') "; realcoop_control = dt.Rows[0]["coop_control"].ToString(); } sql = @" select description, closeday_status, workdate, application, decode((select user_name from amsecuseapps where "+sql_ext+@" and application = a.application and user_name = {1} and rownum <= 1), null, 0, 1) as readable from amappstatus a where coop_id = {0} and used_flag = 1 order by menu_order"; if (Sta.IS_MYSQL_MODE) { sql = @" select description, closeday_status, workdate, application, IF( ( select user_name from amsecuseapps where " + sql_ext + @" and application = a.application and user_name = {1} limit 1) IS NULL,0,1) as readable from amappstatus a where coop_id = {0} and used_flag = 1 order by menu_order "; } sql = WebUtil.SQLFormat(sql, coopControl, username); dt = oracleTA.QueryDataTable(sql); rows = dt.Rows.Count; //กรณี ไม่มีการแยกเปิดปิดวัน ก็ให้ดึงตามสำนักงานใหญ่ if (rows <= 0) { coopControl = realcoop_control; sql_ext = " coop_id in (select coop_id from cmcoopmaster where coop_control= '" + coopControl + "') "; sql = @" select a.description, a.closeday_status, a.workdate, a.application, decode((select user_name from amsecuseapps where " + sql_ext + @" and application = a.application and user_name = {1} and rownum <= 1), null, 0, 1) as readable from amappstatus a , cmcoopmaster c where a.coop_id = c.coop_control and c.coop_id = {0} and a.used_flag = 1 order by menu_order "; sql = WebUtil.SQLFormat(sql, coopControl, username); dt = oracleTA.QueryDataTable(sql); rows = dt.Rows.Count; } } catch { dt = null; } for (int i = 0; i < 24; i++) { MenuApplications m = new MenuApplications(); if (i % 6 == 0) { m.TrStart = ""; } else { m.TrStart = ""; } m.TrEnd = i == 5 || i == 11 || i == 17 || i == 24 ? "" : ""; try { if (dt == null) throw new Exception(); if (rows < i) throw new Exception(); bool isClose = true; string stat = ""; try { isClose = Convert.ToInt32(dt.Rows[i]["closeday_status"]) == 1; } catch { isClose = true; } bool readable = Convert.ToInt32(dt.Rows[i]["readable"]) == 1; stat = isClose ? "[ปิด]" : "[เปิด]"; m.WorkDate = "วันทำการ: " + Convert.ToDateTime(dt.Rows[i]["workdate"]).ToString("dd/MM/yyyy", th) + " " + stat; m.Name = dt.Rows[i]["description"].ToString(); m.Application = dt.Rows[i]["application"].ToString(); m.AppEvent = readable ? dt.Rows[i]["application"].ToString() : ""; m.Picture = WebUtil.GetSavingUrlCore() + "Image/ApplicationsIcon/" + m.Application + ".jpg"; m.PictureCss = readable ? "imApplication" : "imApplicationDeny"; m.AppLableCss = readable ? "lbApplication" : "lbApplicationDeny"; m.WorkDateLableCss = readable ? "lbWorkDateOn" : "lbWorkDateOnDeny"; } catch { m.WorkDate = ""; m.Name = ""; m.Application = ""; m.PageLink = ""; m.Picture = WebUtil.GetSavingUrlCore() + "Image/white.gif"; m.PictureCss = "imApplicationNone"; } menu.Add(m); } return menu; } } }