public IEnumerable <Detail> CreateTicket(TicketModels newItem)
        {
            List <Detail> results = new List <Detail>();

            try
            {
                string tketNo = ticketNo();

                using (TicketLEDataContext Context = new TicketLEDataContext())
                {
                    TASK_MAIN Insert_Main = new TASK_MAIN();

                    Insert_Main.TICKETNO   = tketNo;
                    Insert_Main.DETEIL     = newItem.Add.Detail;
                    Insert_Main.WORKDATE   = DateTime.Now;
                    Insert_Main.STCODE     = newItem.STCODE;
                    Insert_Main.STATUS     = "1";
                    Insert_Main.FLAG       = "1";
                    Insert_Main.APPROVE_ID = 1;

                    Context.TASK_MAINs.InsertOnSubmit(Insert_Main);
                    Context.SubmitChanges();

                    var sql = (from xx in Context.TASK_MAINs
                               where xx.TICKETNO == tketNo
                               select xx).FirstOrDefault();

                    var doc = from xx in Context.MAS_DOCs
                              select xx;
                    int i = 0;
                    foreach (var item in doc)
                    {
                        TASK_SUB Insert_Sub = new TASK_SUB();

                        if (newItem.GetCheck[i].Checked == true)
                        {
                            Insert_Sub.LE_ID      = sql.ID;
                            Insert_Sub.DOC_ID     = newItem.GetCheck[i].ID;
                            Insert_Sub.DETEIL_SUB = newItem.GetCheck[i].NAME;

                            Context.TASK_SUBs.InsertOnSubmit(Insert_Sub);
                            Context.SubmitChanges();
                        }
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                Detail res = new Detail();
                res.status  = "F";
                res.message = ex.Message;
                results.Add(res);
            }

            return(results.ToArray());
        }
        public IEnumerable <TicketModels> CreateTicketShow()
        {
            List <TicketModels> results = new List <TicketModels>();

            try
            {
                TicketModels valus = new TicketModels();

                using (TicketLEDataContext Context = new TicketLEDataContext())
                {
                    var sql = (from xx in Context.MAS_DOCs
                               orderby xx.TYPE
                               select xx);

                    List <CheckBox> list = new List <CheckBox>();

                    //ViewBag.Count = sql.Count();
                    //ViewBag.Check = ViewBag.Count / 2;

                    foreach (var item in sql)
                    {
                        CheckBox ux = new CheckBox();
                        ux.ID   = item.DOC_ID;
                        ux.Doc  = item.DOC_NAME;
                        ux.Type = item.TYPE;

                        list.Add(ux);
                    }

                    valus.GetCheck = list;
                }
                results.Add(valus);
            }
            catch (Exception ex)
            {
                //AnsOP res = new AnsOP();
                //res.status = "F";
                //res.message = ex.Message;
                //results.Add(res);
            }

            return(results.ToArray());
        }
        public IEnumerable <TicketModels> ApproveTicket(Detail data)
        {
            List <TicketModels> results = new List <TicketModels>();

            try
            {
                IQueryable <WebAPI.DATA.TicketLE.VW_TICKET> View_Ticket;
                var seach = data.seach;
                var type  = data.type;

                UserDataContext     Con = new UserDataContext();
                TicketLEDataContext db  = new TicketLEDataContext();

                TicketModels value = new TicketModels();

                //value.Type = new SelectList(db.MAS_SSes, "SS_ID", "SS_NAME");

                var User = (from xx in Con.MAS_USERs
                            join yy in Con.MAS_DEPs on xx.D_ID equals yy.DP_ID
                            where xx.STCODE == data.STCODE
                            select new { xx, yy }).FirstOrDefault();

                //value.DP = User.xx.D_ID;

                using (TicketLEDataContext Context = new TicketLEDataContext())
                {
                    View_Ticket = Context.VW_TICKETs.Where(s => s.TICKETNO.Contains(seach) || s.DPCODE.Contains(seach) || s.NICKNAME.Contains(seach)).Where(s => s.STATUS == "1").Where(s => s.FLAG == "1").Where(s => s.APPROVE_ID == 1).Where(s => s.DPCODE == User.yy.DPCODE).OrderBy(s => s.STATUS);

                    List <Ticket> ticketsAns = new List <Ticket>();

                    foreach (var item in View_Ticket)
                    {
                        Ticket ux = new Ticket();

                        ux.ID           = item.ID;
                        ux.TICKETNO     = item.TICKETNO;
                        ux.DETAIL       = item.DETEIL;
                        ux.CREATEDATE   = DateTime.Parse(item.WORKDATE.ToString()).ToShortDateString();
                        ux.CREATETIME   = DateTime.Parse(item.WORKDATE.ToString()).ToLongTimeString();
                        ux.CRE_NICKNAME = item.NICKNAME;
                        ux.DEP          = item.DPCODE;
                        ux.SSID         = Int32.Parse(item.STATUS);
                        ux.SSNAME       = item.SS_NAME;

                        ticketsAns.Add(ux);
                    }

                    value.TicketDetail = ticketsAns;
                }

                //value.WordSearch = seach;
                //value.typeSearch = type;

                results.Add(value);
            }
            catch (Exception ex)
            {
                //Detail res = new Detail();
                //res.status = "F";
                //res.message = ex.Message;
                //results.Add(res);
            }

            return(results.ToArray());
        }
        public IEnumerable <TicketModels> Print(TicketModels newItem)
        {
            List <TicketModels> results = new List <TicketModels>();

            try
            {
                TicketModels valus = new TicketModels();

                UserDataContext Con = new UserDataContext();

                var User = (from xx in Con.MAS_USERs
                            join yy in Con.MAS_DEPs on xx.D_ID equals yy.DP_ID
                            where xx.STCODE == newItem.STCODE
                            select new { xx, yy }).FirstOrDefault();

                newItem.DP       = User.xx.D_ID;
                newItem.DPNAME   = User.yy.DPCODE;
                newItem.FULLNAME = User.xx.FNAME + " " + User.xx.LNAME;

                using (TicketLEDataContext Context = new TicketLEDataContext())
                {
                    var Main = (from xx in Context.VW_TICKETs
                                where xx.ID == newItem.TicketId
                                select xx).FirstOrDefault();

                    var Sub = (from xx in Context.TASK_SUBs
                               join yy in Context.MAS_DOCs on xx.DOC_ID equals yy.DOC_ID
                               where xx.LE_ID == newItem.TicketId
                               orderby xx.DETEIL_SUB
                               select new { xx, yy });

                    List <CheckBox> lstSub = new List <CheckBox>();

                    int row = 1;
                    foreach (var item in Sub)
                    {
                        CheckBox ux = new CheckBox();

                        ux.row  = row;
                        ux.Doc  = item.yy.DOC_NAME;
                        ux.NAME = item.xx.DETEIL_SUB;
                        ux.Type = item.yy.TYPE;

                        lstSub.Add(ux);
                        row++;
                    }

                    valus.Detail = lstSub;

                    Ticket lis = new Ticket();

                    lis.TICKETNO     = Main.TICKETNO;
                    lis.DETAIL       = Main.DETEIL;
                    lis.CREATEDATE   = DateTime.Parse(Main.WORKDATE.ToString()).ToShortDateString();
                    lis.CREATETIME   = DateTime.Parse(Main.WORKDATE.ToString()).ToLongTimeString();
                    lis.CRE_NICKNAME = Main.NICKNAME;
                    lis.DEP          = Main.DPCODE;
                    lis.SSID         = Int32.Parse(Main.STATUS);
                    lis.SSNAME       = Main.SS_NAME;
                    lis.NAME_OPEN    = Main.FNAME + " " + Main.LNAME;
                    lis.DATE_OPEN    = DateTime.Parse(Main.WORKDATE.ToString()).ToShortDateString();
                    lis.NAME_HDEP    = Main.HDEP_NAME;

                    if (Main.HDEP_DATE != null)
                    {
                        lis.DATE_HDEP = DateTime.Parse(Main.HDEP_DATE.ToString()).ToShortDateString();
                    }

                    lis.NAME_RECEIVE = Main.RECEIVE_NAME;
                    if (Main.RECEIVE_DATE != null)
                    {
                        lis.DATE_RECEIVE = DateTime.Parse(Main.RECEIVE_DATE.ToString()).ToShortDateString();
                    }

                    lis.NAME_CLOSE = Main.CLOSE_NAME;
                    if (Main.CLOSE_DATE != null)
                    {
                        lis.DATE_CLOSE = DateTime.Parse(Main.CLOSE_DATE.ToString()).ToShortDateString();
                    }

                    valus.TicketSub = lis;
                }

                valus.TicNo = newItem.TicketId;

                results.Add(valus);
            }
            catch (Exception ex)
            {
                //Detail res = new Detail();
                //res.status = "F";
                //res.message = ex.Message;
                //results.Add(res);
            }

            return(results.ToArray());
        }