Ejemplo n.º 1
0
        public ActionResult cardlogtransfer3(string sysflag, conbudgetdet col, HttpPostedFileBase upfile)
        {
            // ViewBag.pid = Request["pid"].ToString();

            if (sysflag != "A")
            {
                return(View());
            }
            else
            {
                NDcommon dbobj  = new NDcommon();
                string   errmsg = "";
                if (upfile != null)
                {
                    String sernonum = "";
                    //重新命名,存入檔案
                    DateTime myDate = DateTime.Now;
                    sernonum = myDate.ToString("yyyyMMddHHmmss");
                    string BasicPath = Server.MapPath("~/upload/");
                    string fileName  = upfile.FileName.Substring(upfile.FileName.IndexOf("."), upfile.FileName.Length - upfile.FileName.IndexOf("."));

                    if (fileName != ".exe" && fileName != ".asp" && fileName != ".aspx" && fileName != ".jsp" && fileName != ".php")
                    {
                        fileName = "cust-" + sernonum.ToString() + fileName;
                        upfile.SaveAs(Server.MapPath("~/upload/") + fileName);

                        string tmppath = BasicPath + fileName;


                        StreamReader sr     = new StreamReader(@tmppath, System.Text.Encoding.Default);
                        string       allstr = sr.ReadToEnd(); //從資料流末端存取檔案
                        sr.Close();

                        string[] tmpstridno; //匯入資料

                        allstr     = allstr.Replace(Environment.NewLine, "\"");
                        allstr     = allstr.Substring(0, allstr.Length - 1);
                        tmpstridno = allstr.Split('\"');

                        //tmpstridno[0] = GetBytesCount1(tmpstridno[0]);


                        #region

                        string        tempcard = "", tempcard1 = "", tempdatetime = "", tmptime = "";
                        SqlConnection comconn = dbobj.get_conn("Aitag_DBContext");
                        foreach (string tmptxt in tmpstridno)
                        {
                            if (tmptxt != "")
                            {
                                tempcard     = tmptxt.Trim().Substring(0, 10);
                                tempcard1    = tmptxt.Trim().Substring(11, 4);
                                tempdatetime = tmptxt.Trim().Substring(16, 8);
                                tmptime      = tmptxt.Trim().Substring(25, 4);

                                if (tempcard != "" && tempcard1 != "" && tempdatetime != "" && tmptime != "")
                                {
                                    string date1 = tempdatetime.Substring(0, 4) + "/" + tempdatetime.Substring(4, 2) + "/" + tempdatetime.Substring(6, 2);
                                    tmptime = tmptime + "00";

                                    string rs1_Open = ""; rs1_Open = dbobj.get_dbvalue(comconn, "select * from cardreallog where clogtime = '" + tmptime + "' and clogdate = '" + date1 + "' and tmpcardno = '" + tempcard1 + "'");
                                    if (rs1_Open == "")
                                    {
                                        using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                                        {
                                            string sql = "select empid,empname,empworkdepid,empworkcomp from employee where empno = '" + tempcard1 + "'";
                                            using (SqlCommand cmd = new SqlCommand(sql, conn))
                                            {
                                                SqlDataReader dr = cmd.ExecuteReader();
                                                if (dr.HasRows)
                                                {
                                                    cardreallog rs = new cardreallog();
                                                    dr.Read();

                                                    rs.empid     = dr["empid"] + "";
                                                    rs.empname   = dr["empname"] + "";
                                                    rs.dptid     = dr["empworkdepid"] + "";
                                                    rs.comid     = dr["empworkcomp"] + "";
                                                    rs.clogdate  = DateTime.Parse(date1);
                                                    rs.clogtime  = tmptime;
                                                    rs.tmpcardno = tempcard1;
                                                    rs.tmpdepid  = dbobj.get_dbvalue(comconn, "select dpttitle from department where dptid='" + dr["empworkdepid"] + "'");

                                                    using (Aitag_DBContext con = new Aitag_DBContext())
                                                    {
                                                        con.cardreallog.Add(rs);
                                                        con.SaveChanges();
                                                    }
                                                }
                                                else
                                                {
                                                    errmsg += tempcard1 + ",";
                                                }
                                                dr.Close();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        comconn.Close();
                        comconn.Dispose();
                        #endregion
                    }
                    else
                    {
                        ViewBag.AddModelError = @"alert('上傳格式錯誤!');";
                        return(View());
                    }
                }


                string tmpform = "";
                if (errmsg != "")
                {
                    tmpform += "<script>";
                    tmpform += "function SetParentOpener() {";
                    tmpform += "alert('以下員編尚未轉檔,請確認!!" + errmsg + "');";
                    tmpform += "parent.opener.location.href='/cardreallog/List';";
                    tmpform += "window.close();";
                    tmpform += "}";
                    tmpform += "</script>";
                    tmpform += "<body onload=SetParentOpener();>";
                    //tmpform += errmsg;
                    tmpform += "</body>";
                }
                else
                {
                    tmpform += "<script>";
                    tmpform += "function SetParentOpener() {";
                    tmpform += "alert('轉檔成功!!');";
                    tmpform += "parent.opener.location.href='/cardreallog/List';";
                    tmpform += "window.close();";
                    tmpform += "}";
                    tmpform += "</script>";
                    tmpform += "<body onload=SetParentOpener();>";
                    tmpform += "</body>";
                }


                return(new ContentResult()
                {
                    Content = @"" + tmpform
                });
            }
        }
Ejemplo n.º 2
0
        //[HttpGet]
        //public ActionResult Add()
        //{
        //    ViewBag.Ifboss = Session["Ifboss"].ToString();
        //    ViewBag.crid = Session["crid"].ToString();
        //    cardreallog col = new cardreallog();
        //    return View(col);
        //}

        //[HttpPost]
        public ActionResult add(cardreallog 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 = "crid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qdptid = "", qempname = "", qclogsdate = "", qclogedate = "";

            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["qclogsdate"]))
            {
                qclogsdate         = Request["qclogsdate"].Trim();
                ViewBag.qclogsdate = qclogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qclogedate"]))
            {
                qclogedate         = Request["qclogedate"].Trim();
                ViewBag.qclogedate = qclogedate;
            }

            if (sysflag != "A")
            {
                cardreallog newcol = new cardreallog();

                ViewBag.cloghour = ViewBagcloghour("");
                ViewBag.clogmin  = ViewBagclogmin("");

                return(View(newcol));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(col));
                }
                else
                {
                    NDcommon      dbobj = new NDcommon();
                    SqlConnection conn  = dbobj.get_conn("Aitag_DBContext");
                    SqlDataReader dr;
                    SqlCommand    sqlsmd = new SqlCommand();
                    sqlsmd.Connection = conn;
                    string sqlstr = "select crid from cardreallog where crid = '" + col.crid + "'";
                    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.clogtime  = Request["cloghour"].Trim() + Request["clogmin"].Trim() + "00";
                    col.comid     = Session["comid"].ToString();
                    col.tmpcardno = Request["cardno"].Trim();
                    col.tmpdepid  = Request["dptidname"].Trim();
                    col.bmodid    = Session["tempid"].ToString();
                    col.bmoddate  = DateTime.Now;
                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        con.cardreallog.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.empname + "<br>刷卡日期:" + col.clogdate + " " + Request["cloghour"].Trim() + Request["clogmin"].Trim() + "的資料";
                        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='/cardreallog/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='qclogsdate' name='qclogsdate' value='" + qclogsdate + "'>";
                    tmpform += "<input type=hidden id='qclogedate' name='qclogedate' value='" + qclogedate + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";


                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                    // return RedirectToAction("List");
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult cardbatch(string sysflag)
        {
            ModelState.Clear();

            string sid = "", realsid = "", yhid = "", carddate = "", ctype = "";

            if (!string.IsNullOrWhiteSpace(Request["sid"]))
            {
                sid         = Request["sid"].Trim();
                ViewBag.sid = sid;
            }
            if (!string.IsNullOrWhiteSpace(Request["realsid"]))
            {
                realsid         = Request["realsid"].Trim();
                ViewBag.realsid = realsid;
            }
            if (!string.IsNullOrWhiteSpace(Request["yhid"]))
            {
                yhid         = Request["yhid"].Trim();
                ViewBag.yhid = yhid;
            }
            if (!string.IsNullOrWhiteSpace(Request["carddate"]))
            {
                carddate         = Request["carddate"].Trim();
                ViewBag.carddate = DateTime.Parse(carddate);
            }
            if (!string.IsNullOrWhiteSpace(Request["ctype"]))
            {
                ctype         = Request["ctype"].Trim();
                ViewBag.ctype = ctype;
            }
            if (sysflag != "A")
            {
                return(View());
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                else
                {
                    NDcommon dbobj = new NDcommon();
                    //'取得這類人員的上下班時間
                    string ytstime = "", ydetime = "";
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        string sql = "select * from yearholiday where yhid = '" + yhid + "'";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.HasRows)
                            {
                                dr.Read();
                                ytstime = dbobj.get_dbnull2(dr["ytstime"]);
                                ydetime = dbobj.get_dbnull2(dr["ydetime"]);
                            }
                            dr.Close();
                        }
                    }
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        string sql = "select * from employee where empstatus in ('1','2') and yhid = '" + yhid + "'";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr = cmd.ExecuteReader();

                            string clogtime = "";
                            if (ctype == "1")
                            {
                                clogtime = ytstime;
                            }
                            else
                            {
                                clogtime = ydetime;
                            }
                            var bmoddate = DateTime.Now;
                            while (dr.Read())
                            {
                                cardreallog col = new cardreallog();

                                col.empid    = dbobj.get_dbnull2(dr["empid"]);
                                col.empname  = dbobj.get_dbnull2(dr["empname"]);
                                col.dptid    = dbobj.get_dbnull2(dr["empworkdepid"]);
                                col.clogdate = ViewBag.carddate;
                                col.clogtime = clogtime;

                                col.comid    = Session["comid"].ToString();
                                col.bmodid   = Session["tempid"].ToString();
                                col.bmoddate = bmoddate;

                                using (Aitag_DBContext con = new Aitag_DBContext())
                                {
                                    con.cardreallog.Add(col);
                                    con.SaveChanges();
                                }
                            }
                            dr.Close();
                        }
                    }

                    //系統LOG檔 //================================================= //
                    SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                    string        sysrealsid = Request["sysrealsid"].ToString();
                    string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                    string        sysnote    = "班別代碼:" + yhid + "<br>產生日期:" + carddate + "的資料";
                    dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                    sysconn.Close();
                    sysconn.Dispose();
                    //=================================================

                    string tmpform = "";
                    tmpform += "<script>";
                    tmpform += "function SetParentOpener() {";
                    tmpform += "alert('刷卡資料批次產生成功!!');";
                    tmpform += "parent.opener.location.href='/cardreallog/List';";
                    tmpform += "window.close();";
                    tmpform += "}";
                    tmpform += "</script>";

                    tmpform += "<body onload=SetParentOpener();>";
                    tmpform += "</body>";
                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                }
            }
        }
Ejemplo n.º 4
0
        public ActionResult Edit(cardreallog 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 = "crid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qdptid = "", qempname = "", qclogsdate = "", qclogedate = "";

            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["qclogsdate"]))
            {
                qclogsdate         = Request["qclogsdate"].Trim();
                ViewBag.qclogsdate = qclogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qclogedate"]))
            {
                qclogedate         = Request["qclogedate"].Trim();
                ViewBag.qclogedate = qclogedate;
            }

            if (sysflag != "E")
            {
                using (Aitag_DBContext con = new Aitag_DBContext())
                {
                    var         data          = con.cardreallog.Where(r => r.crid == chks.crid).FirstOrDefault();
                    cardreallog ecardreallogs = con.cardreallog.Find(chks.crid);
                    if (ecardreallogs == null)
                    {
                        return(HttpNotFound());
                    }


                    ViewBag.cloghour = ViewBagcloghour(ecardreallogs.clogtime.Substring(0, 2));
                    ViewBag.clogmin  = ViewBagclogmin(ecardreallogs.clogtime.Substring(2, 2));

                    return(View(ecardreallogs));
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(chks));
                }
                else
                {
                    //string oldcrid = Request["oldcrid"];

                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        NDcommon dbobj = new NDcommon();

                        chks.clogtime         = Request["cloghour"].Trim() + Request["clogmin"].Trim() + "00";
                        chks.tmpcardno        = Request["cardno"].Trim();
                        chks.tmpdepid         = Request["dptidname"].Trim();
                        chks.bmodid           = Session["tempid"].ToString();
                        chks.bmoddate         = DateTime.Now;
                        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.empname + "<br>刷卡日期:" + chks.clogdate + " " + Request["cloghour"].Trim() + Request["clogmin"].Trim() + "的資料";
                        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='/cardreallog/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='qclogsdate' name='qclogsdate' value='" + qclogsdate + "'>";
                        tmpform += "<input type=hidden id='qclogedate' name='qclogedate' value='" + qclogedate + "'>";
                        tmpform += "</form>";
                        tmpform += "</body>";


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