Ejemplo n.º 1
0
        public ActionResult fileuploadDB()
        {
            string realsid = Request["realsid"].ToString();
            string mcid    = Request["mcid"].ToString();

            if (mcid == "")
            {
                mcid = Session["mcid"].ToString();
            }
            string qmcparentid = Request["qmcparentid"].ToString();

            string   cfilename = Request["cfilename"].ToString();
            string   vfilename = Request["vfilename"].ToString();
            string   cfilesize = Request["cfilesize"].ToString();
            NDcommon dbobj     = new NDcommon();


            System.IO.File.Copy(Server.MapPath(Imglink + "/upload/" + cfilename), Server.MapPath(Imglink + "/upload/" + vfilename));
            System.IO.File.Delete(Server.MapPath(Imglink + "/upload/" + cfilename));

            using (Aitag_DBContext con = new Aitag_DBContext())
            {
                SqlConnection conn = dbobj.get_conn("Aitag_DBContext");
                SqlDataReader dr;
                SqlCommand    sqlsmd = new SqlCommand();
                sqlsmd.Connection = conn;
                //取得功能代號

                string sqlstr = "select * from sublevel1 where sid = '" + realsid + "'";
                sqlsmd.CommandText = sqlstr;
                dr = sqlsmd.ExecuteReader();
                string functype = "";
                if (dr.Read())
                {
                    functype = dr["functype"].ToString();
                }

                dr.Close();
                dr.Dispose();

                if (mcid == "")
                {
                    maincontent mainobj = new maincontent();

                    if (qmcparentid != "")
                    {
                        mainobj.mcparentid = int.Parse(qmcparentid);
                    }
                    mainobj.mctitle    = "";
                    mainobj.mchttp     = "";
                    mainobj.mctype     = functype;
                    mainobj.sid        = int.Parse(realsid);
                    mainobj.readallman = "";
                    mainobj.mdate      = DateTime.Today;
                    mainobj.mclick     = 0;
                    mainobj.ownman     = Session["empid"].ToString();
                    mainobj.comid      = Session["comid"].ToString();
                    mainobj.bmodid     = Session["empid"].ToString();
                    mainobj.bmoddate   = DateTime.Today;
                    con.maincontent.Add(mainobj);
                    con.SaveChanges();

                    sqlstr             = "select top 1 * from maincontent where ownman = '" + Session["empid"].ToString() + "' order by mcid desc";
                    sqlsmd.CommandText = sqlstr;
                    dr = sqlsmd.ExecuteReader();
                    if (dr.Read())
                    {
                        mcid = dr["mcid"].ToString();
                    }

                    dr.Close();
                    dr.Dispose();

                    Session["mcid"] = mcid;
                }

                conn.Close();
                conn.Dispose();

                contupload addobj = new contupload();
                addobj.cfilename  = cfilename;
                addobj.cfilesize  = int.Parse(cfilesize);
                addobj.mcid       = int.Parse(mcid);
                addobj.cfiletitle = cfilename;
                addobj.cupfile    = vfilename;

                addobj.bmodid   = Session["empid"].ToString();
                addobj.bmoddate = DateTime.Now;

                con.contupload.Add(addobj);
                con.SaveChanges();
                con.Dispose();
            }
            string tmpdata = mcid;

            return(new ContentResult()
            {
                Content = @"" + tmpdata
            });
        }
Ejemplo n.º 2
0
        public ActionResult Edit(schedule chks, string sysflag, HttpPostedFileBase sfile1)
        {
            if (!string.IsNullOrWhiteSpace(Request["year1"]))
            {
                ViewBag.year1 = Request["year1"].ToString();
            }
            else
            {
                ViewBag.year1 = "";
            }

            if (!string.IsNullOrWhiteSpace(Request["month1"]))
            {
                ViewBag.month1 = Request["month1"].ToString();
            }
            else
            {
                ViewBag.month1 = "";
            }

            if (!string.IsNullOrWhiteSpace(Request["qschdate"]))
            {
                ViewBag.qschdate = Request["qschdate"].ToString();
            }
            else
            {
                ViewBag.qschdate = "";
            }

            ViewBag.schtype = Request["schtype"].ToString();
            ViewBag.Mflag   = Request["Mflag"].ToString();

            int schid = int.Parse(Request["schid"].ToString());

            if (sysflag != "E")
            {
                using (Aitag_DBContext con = new Aitag_DBContext())
                {
                    var      data     = con.schedule.Where(r => r.schid == chks.schid).FirstOrDefault();
                    schedule schedule = con.schedule.Find(chks.schid);
                    if (schedule == null)
                    {
                        return(HttpNotFound());
                    }
                    return(View(schedule));
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(chks));
                }
                else
                {
                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        schedule modobj = con.schedule.Where(r => r.schid == schid).FirstOrDefault();

                        string schtitle = Request["schtitle"].ToString().Trim();
                        schtitle = schtitle.Replace("'", "’");

                        modobj.schtitle   = schtitle;
                        modobj.schcontent = Request["schcontent"].ToString().Trim();
                        modobj.schplace   = Request["schplace"].ToString().Trim();
                        modobj.schdate    = DateTime.Parse(Request["schdate"].ToString());
                        modobj.schhour    = Request["schhour"].ToString().Trim();
                        modobj.schmin     = Request["schmin"].ToString().Trim();
                        modobj.schehour   = Request["schehour"].ToString().Trim();
                        modobj.schemin    = Request["schemin"].ToString().Trim();


                        #region  傳檔案

                        if (sfile1 != null)
                        {
                            string sernonum;
                            //重新命名,存入檔案
                            DateTime myDate = DateTime.Now;
                            sernonum = myDate.ToString("yyyyMMddHHmmss");

                            string fileName = sfile1.FileName.Substring(sfile1.FileName.IndexOf("."), sfile1.FileName.Length - sfile1.FileName.IndexOf("."));

                            if (fileName != ".exe" && fileName != ".asp" && fileName != ".aspx" && fileName != ".jsp" && fileName != ".php")
                            {
                                fileName = "F-" + sernonum.ToString() + fileName;

                                sfile1.SaveAs(Server.MapPath("~/Upload/") + fileName);
                                modobj.sfile = fileName;
                            }
                        }
                        #endregion


                        con.Entry(modobj).State = EntityState.Modified;
                        con.SaveChanges();
                        con.Dispose();

                        Aitag.Models.NDcommon dbobj = new Aitag.Models.NDcommon();

                        //系統LOG檔 //================================================= //
                        SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                        string        sysrealsid = Request["sysrealsid"].ToString();
                        string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                        string        sysnote    = "分類:" + Request["tmptitle"].ToString() + "<br>標題:" + schtitle + "<br>日期:" + Request["schdate"].ToString();
                        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='/schedule/List' method='post'>";
                        tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
                        tmpform += "<input type=hidden name='year1' id='year1' value='" + ViewBag.year1 + "'>";
                        tmpform += "<input type=hidden name='month1' id='month1' value='" + ViewBag.month1 + "'>";
                        tmpform += "<input type=hidden name='Mflag' id='Mflag' value='" + ViewBag.Mflag + "'>";
                        tmpform += "<input type=hidden name='qschdate' id='qschdate' value='" + ViewBag.qschdate + "'>";
                        tmpform += "</form>";
                        tmpform += "</body>";


                        return(new ContentResult()
                        {
                            Content = @"<script>alert('修改成功!!');</script>" + tmpform
                        });
                    }
                }
            }
        }