示例#1
0
        //[HttpGet]
        //public ActionResult Add()
        //{
        //    ViewBag.Ifboss = Session["Ifboss"].ToString();
        //    ViewBag.Msid = Session["Msid"].ToString();
        //    Checkcode col = new Checkcode();
        //    return View(col);
        //}

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

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qchkclass = "", qchkitem = "";

            if (!string.IsNullOrWhiteSpace(Request["qchkclass"]))
            {
                qchkclass         = Request["qchkclass"].Trim();
                ViewBag.qchkclass = qchkclass;
            }
            if (!string.IsNullOrWhiteSpace(Request["qchkitem"]))
            {
                qchkitem         = Request["qchkitem"].Trim();
                ViewBag.qchkitem = qchkitem;
            }

            if (sysflag != "A")
            {
                Checkcode newcol = new Checkcode();
                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 cid from Checkcode where chkclass = '" + col.chkclass + "' and chkcode = '" + col.chkcode + "'";
                    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.emppasswd = dbobj.Encrypt(col.emppasswd);
                    //col.chkclass = col.emppasswd;
                    //col.baddid = Session["tempid"].ToString();
                    col.bmodid = Session["tempid"].ToString();
                    //col.badddate = DateTime.Now;
                    col.bmoddate = DateTime.Now;
                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        con.Checkcode.Add(col);
                        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    = "類別:" + col.chkclasstitle + "代碼名稱:" + col.chkitem;
                        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='/Checkcode/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='qchkclass' name='qchkclass' value='" + qchkclass + "'>";
                    tmpform += "<input type=hidden id='qchkitem' name='qchkitem' value='" + qchkitem + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";


                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                    // return RedirectToAction("List");
                }
            }
        }
示例#2
0
        public ActionResult Edit(Checkcode 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 = "cid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qchkclass = "", qchkitem = "";

            if (!string.IsNullOrWhiteSpace(Request["qchkclass"]))
            {
                qchkclass         = Request["qchkclass"].Trim();
                ViewBag.qchkclass = qchkclass;
            }
            if (!string.IsNullOrWhiteSpace(Request["qchkitem"]))
            {
                qchkitem         = Request["qchkitem"].Trim();
                ViewBag.qchkitem = qchkitem;
            }

            if (sysflag != "E")
            {
                using (Aitag_DBContext con = new Aitag_DBContext())
                {
                    var       data        = con.Checkcode.Where(r => r.cid == chks.cid).FirstOrDefault();
                    Checkcode eCheckcodes = con.Checkcode.Find(chks.cid);
                    if (eCheckcodes == null)
                    {
                        return(HttpNotFound());
                    }
                    return(View(eCheckcodes));
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(chks));
                }
                else
                {
                    //string oldmsid = Request["oldmsid"];

                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        NDcommon dbobj = new NDcommon();
                        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.chkclasstitle + "代碼名稱:" + chks.chkitem;
                        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='/Checkcode/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='qchkclass' name='qchkclass' value='" + qchkclass + "'>";
                        tmpform += "<input type=hidden id='qchkitem' name='qchkitem' value='" + qchkitem + "'>";
                        tmpform += "</form>";
                        tmpform += "</body>";


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