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

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

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qcomclass = "", qitemcode = "", qsubjecttitle = "";

            if (!string.IsNullOrWhiteSpace(Request["qcomclass"]))
            {
                qcomclass         = Request["qcomclass"].Trim();
                ViewBag.qcomclass = qcomclass;
            }
            if (!string.IsNullOrWhiteSpace(Request["qitemcode"]))
            {
                qitemcode         = Request["qitemcode"].Trim();
                ViewBag.qitemcode = qitemcode;
            }
            if (!string.IsNullOrWhiteSpace(Request["qsubjecttitle"]))
            {
                qsubjecttitle         = Request["qsubjecttitle"].Trim();
                ViewBag.qsubjecttitle = qsubjecttitle;
            }

            if (sysflag != "A")
            {
                billsubject newcol = new billsubject();
                return(View(newcol));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(col));
                }
                else
                {
                    Aitag.Models.NDcommon dbobj = new Aitag.Models.NDcommon();
                    SqlConnection         conn  = dbobj.get_conn("AitagBill_DBContext");
                    SqlDataReader         dr;
                    SqlCommand            sqlsmd = new SqlCommand();
                    sqlsmd.Connection = conn;
                    string sqlstr = "select accid from billsubject where comid = '" + Session["comid"] + "' and itemcode = '" + col.itemcode + "'";
                    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.comid  = Session["tempid"].ToString();
                    col.bmodid = Session["tempid"].ToString();
                    //col.badddate = DateTime.Now;
                    col.bmoddate = DateTime.Now;
                    using (AitagBill_DBContext con = new AitagBill_DBContext())
                    {
                        con.billsubject.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.comclass + "代碼名稱:" + col.subjecttitle;
                        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='/billsubject/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='qcomclass' name='qcomclass' value='" + qcomclass + "'>";
                    tmpform += "<input type=hidden id='qsubjecttitle' name='qsubjecttitle' value='" + qsubjecttitle + "'>";
                    tmpform += "<input type=hidden id='qitemcode' name='qitemcode' value='" + qitemcode + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";


                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                    // return RedirectToAction("List");
                }
            }
        }
예제 #2
0
        public ActionResult Edit(billsubject 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 = "accid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qcomclass = "", qitemcode = "", qsubjecttitle = "";

            if (!string.IsNullOrWhiteSpace(Request["qcomclass"]))
            {
                qcomclass         = Request["qcomclass"].Trim();
                ViewBag.qcomclass = qcomclass;
            }
            if (!string.IsNullOrWhiteSpace(Request["qitemcode"]))
            {
                qitemcode         = Request["qitemcode"].Trim();
                ViewBag.qitemcode = qitemcode;
            }
            if (!string.IsNullOrWhiteSpace(Request["qsubjecttitle"]))
            {
                qsubjecttitle         = Request["qsubjecttitle"].Trim();
                ViewBag.qsubjecttitle = qsubjecttitle;
            }

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

                    using (AitagBill_DBContext con = new AitagBill_DBContext())
                    {
                        NDcommon dbobj = new NDcommon();
                        chks.comid            = Session["comid"].ToString();
                        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.comclass + "代碼名稱:" + chks.subjecttitle;
                        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='/billsubject/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='qcomclass' name='qcomclass' value='" + qcomclass + "'>";
                        tmpform += "<input type=hidden id='qsubjecttitle' name='qsubjecttitle' value='" + qsubjecttitle + "'>";
                        tmpform += "<input type=hidden id='qitemcode' name='qitemcode' value='" + qitemcode + "'>";
                        tmpform += "</form>";
                        tmpform += "</body>";


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