//[HttpGet]
        //public ActionResult Add()
        //{
        //    ViewBag.Ifboss = Session["Ifboss"].ToString();
        //    ViewBag.rsid = Session["rsid"].ToString();
        //    resthourlog col = new resthourlog();
        //    return View(col);
        //}

        //[HttpPost]
        public ActionResult add(resthourlog col, string sysflag, int?page, string orderdata, string orderdata1)
        {
            ModelState.Clear();
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "rsid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qdptid = "", qempname = "", qaddtype = "", qaddsdate = "", qaddedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qdptid"]))
            {
                qdptid         = Request["qdptid"].Trim();
                ViewBag.qdptid = qdptid;
            }
            if (!string.IsNullOrWhiteSpace(Request["qempname"]))
            {
                qempname         = Request["qempname"].Trim();
                ViewBag.qempname = qempname;
            }
            if (!string.IsNullOrWhiteSpace(Request["qaddtype"]))
            {
                qaddtype         = Request["qaddtype"].Trim();
                ViewBag.qaddtype = qaddtype;
            }
            if (!string.IsNullOrWhiteSpace(Request["qaddsdate"]))
            {
                qaddsdate         = Request["qaddsdate"].Trim();
                ViewBag.qaddsdate = qaddsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qaddedate"]))
            {
                qaddedate         = Request["qaddedate"].Trim();
                ViewBag.qaddedate = qaddedate;
            }

            if (sysflag != "A")
            {
                resthourlog newcol = new resthourlog();
                return(View(newcol));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(col));
                }
                else
                {
                    Aitag.Models.NDcommon dbobj = new Aitag.Models.NDcommon();
                    SqlConnection         conn  = dbobj.get_conn("Aitag_DBContext");
                    SqlDataReader         dr;
                    SqlCommand            sqlsmd = new SqlCommand();
                    sqlsmd.Connection = conn;
                    string sqlstr = "select rsid from resthourlog where rsid = '" + col.rsid + "'";
                    sqlsmd.CommandText = sqlstr;
                    dr = sqlsmd.ExecuteReader();

                    if (dr.Read())
                    {
                        ModelState.AddModelError("", "權限代碼重複!");
                        return(View(col));
                    }
                    dr.Close();
                    dr.Dispose();
                    sqlsmd.Dispose();
                    conn.Close();
                    conn.Dispose();


                    col.otlogid  = 0;
                    col.resmoney = 0;
                    col.inout    = "0";
                    col.comid    = Session["comid"].ToString();

                    col.bmodid   = Session["tempid"].ToString();
                    col.bmoddate = DateTime.Now;
                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        con.resthourlog.Add(col);
                        try
                        {
                            con.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }



                        //系統LOG檔 //================================================= //
                        SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                        string        sysrealsid = Request["sysrealsid"].ToString();
                        string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                        string        sysnote    = "代碼:" + col.rsid + "名稱:" + col.empid;
                        dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                        sysconn.Close();
                        sysconn.Dispose();
                        //=================================================
                    }
                    string tmpform = "";
                    tmpform  = "<body onload=qfr1.submit();>";
                    tmpform += "<form name='qfr1' action='/resthourcheck1/List' method='post'>";
                    tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
                    tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
                    tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
                    tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";
                    tmpform += "<input type=hidden id='qdptid' name='qdptid' value='" + qdptid + "'>";
                    tmpform += "<input type=hidden id='qempname' name='qempname' value='" + qempname + "'>";
                    tmpform += "<input type=hidden id='qaddtype' name='qaddtype' value='" + qaddtype + "'>";
                    tmpform += "<input type=hidden id='qaddsdate' name='qaddsdate' value='" + qaddsdate + "'>";
                    tmpform += "<input type=hidden id='qaddedate' name='qaddedate' value='" + qaddedate + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";


                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                    // return RedirectToAction("List");
                }
            }
        }
        private void delholidayMode(delholidaylog col, string hdellogstatus)
        {
            NDcommon dbobj = new NDcommon();

            using (SqlConnection comconn = dbobj.get_conn("Aitag_DBContext"))
            {
                if (col.hdayid == "A04")
                {
                    #region  '請補假部分
                    resthourlog chks = new resthourlog();
                    chks.empid      = col.empid;
                    chks.rsdeaddate = col.hlogsdate;

                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        var   eresthourlogs = con.resthourlog.Where(r => r.empid == chks.empid && r.rsdeaddate >= chks.rsdeaddate).OrderBy(r => r.rsdeaddate);
                        float tmphloghour   = float.Parse(col.hloghour.ToString());
                        foreach (resthourlog es in eresthourlogs)
                        {
                            var lefthour = es.usehour - tmphloghour;
                            if (lefthour >= 0)
                            {
                                es.usehour -= tmphloghour;
                                using (Aitag_DBContext con2 = new Aitag_DBContext())
                                {
                                    con2.Entry(es).State = EntityState.Modified;
                                    con2.SaveChanges();
                                }
                                if (lefthour == 0)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                es.usehour = 0;
                                using (Aitag_DBContext con2 = new Aitag_DBContext())
                                {
                                    con2.Entry(es).State = EntityState.Modified;
                                    con2.SaveChanges();
                                }
                                tmphloghour = float.Parse(Math.Abs(decimal.Parse(lefthour.ToString())).ToString());
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region  事實發生假部分
                    string   mergehdayid = dbobj.get_dbvalue(comconn, "select * from holidaycode where hdayid = '" + col.hdayid + "'");;
                    string   sql         = "";
                    emphdlog chks        = new emphdlog();


                    if (mergehdayid != "")
                    {
                        chks.empid  = col.empid;
                        chks.hdayid = mergehdayid;
                    }
                    else
                    {
                        chks.empid  = col.empid;
                        chks.hdayid = col.hdayid;
                    }
                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        emphdlog eemphdlogs = con.emphdlog.Where(r => r.empid == chks.empid && r.hdayid == chks.hdayid).FirstOrDefault();

                        if (eemphdlogs != null)
                        {
                            eemphdlogs.usehour          = eemphdlogs.usehour - decimal.Parse(col.hloghour.ToString());
                            con.Entry(eemphdlogs).State = EntityState.Modified;
                            con.SaveChanges();

                            if (eemphdlogs.usehour == 0)
                            {
                                if (mergehdayid != "")
                                {
                                    sql = "delete emphdlog where empid = '" + col.empid + "' and hdayid = '" + mergehdayid + "'";
                                }
                                else
                                {
                                    sql = "delete emphdlog where empid = '" + col.empid + "' and hdayid = '" + col.hdayid + "'";
                                }
                                dbobj.dbexecute("Aitag_DBContext", sql);
                            }
                        }
                    }
                    #endregion
                }
            }
        }
        public ActionResult Edit(resthourlog chks, string sysflag, int?page, string orderdata, string orderdata1)
        {
            ModelState.Clear();
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "rsid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qdptid = "", qempname = "", qaddtype = "", qaddsdate = "", qaddedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qdptid"]))
            {
                qdptid         = Request["qdptid"].Trim();
                ViewBag.qdptid = qdptid;
            }
            if (!string.IsNullOrWhiteSpace(Request["qempname"]))
            {
                qempname         = Request["qempname"].Trim();
                ViewBag.qempname = qempname;
            }
            if (!string.IsNullOrWhiteSpace(Request["qaddtype"]))
            {
                qaddtype         = Request["qaddtype"].Trim();
                ViewBag.qaddtype = qaddtype;
            }
            if (!string.IsNullOrWhiteSpace(Request["qaddsdate"]))
            {
                qaddsdate         = Request["qaddsdate"].Trim();
                ViewBag.qaddsdate = qaddsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qaddedate"]))
            {
                qaddedate         = Request["qaddedate"].Trim();
                ViewBag.qaddedate = qaddedate;
            }

            if (sysflag != "E")
            {
                using (Aitag_DBContext con = new Aitag_DBContext())
                {
                    var         data          = con.resthourlog.Where(r => r.rsid == chks.rsid).FirstOrDefault();
                    resthourlog eresthourlogs = con.resthourlog.Find(chks.rsid);
                    if (eresthourlogs == null)
                    {
                        return(HttpNotFound());
                    }
                    return(View(eresthourlogs));
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    string otlogstime           = "";
                    Aitag.Models.NDcommon dbobj = new Aitag.Models.NDcommon();
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        //                    string tmpwhere = " where osno = '" + Model.osno + "'", otlogstime = "", otlogetime = "";
                        //otlogstime = dbobj.get_dbvalue(comconn,"select otlogstime from otworklog" + tmpwhere);
                        //otlogetime = dbobj.get_dbvalue(comconn,"select otlogetime from otworklog" + tmpwhere);
                        //if (otlogstime != "" && otlogetime != "")
                        //{
                        //    @:@otlogstime ~ @otlogetime
                        //}
                    }
                    return(View(chks));
                }
                else
                {
                    //string oldrsid = Request["oldrsid"];

                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        NDcommon dbobj = new NDcommon();
                        chks.rsid     = int.Parse(Request["rsid"].Trim());
                        chks.bmodid   = Session["tempid"].ToString();
                        chks.bmoddate = DateTime.Now;
                        if (chks.inout == null)
                        {
                            chks.inout = "";
                        }
                        con.Entry(chks).State = EntityState.Modified;
                        con.SaveChanges();


                        //系統LOG檔
                        //================================================= //
                        SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                        string        sysrealsid = Request["sysrealsid"].ToString();
                        string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                        string        sysnote    = "代碼:" + chks.rsid + "名稱:" + chks.empid;
                        dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                        sysconn.Close();
                        sysconn.Dispose();
                        //=================================================

                        string tmpform = "";
                        tmpform  = "<body onload=qfr1.submit();>";
                        tmpform += "<form name='qfr1' action='/resthourcheck1/List' method='post'>";
                        tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
                        tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
                        tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
                        tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";
                        tmpform += "<input type=hidden id='qdptid' name='qdptid' value='" + qdptid + "'>";
                        tmpform += "<input type=hidden id='qempname' name='qempname' value='" + qempname + "'>";
                        tmpform += "<input type=hidden id='qaddtype' name='qaddtype' value='" + qaddtype + "'>";
                        tmpform += "<input type=hidden id='qaddsdate' name='qaddsdate' value='" + qaddsdate + "'>";
                        tmpform += "<input type=hidden id='qaddedate' name='qaddedate' value='" + qaddedate + "'>";
                        tmpform += "</form>";
                        tmpform += "</body>";


                        return(new ContentResult()
                        {
                            Content = @"" + tmpform
                        });
                        //return RedirectToAction("List");
                    }
                }
            }
        }