Ejemplo n.º 1
0
    protected void BtnSaveToCloud_Click(object sender, EventArgs e)
    {
        if (Fupload.HasFile)
        {
            LblMsg.Text = "";
            String filename      = Fupload.FileName.ToLower().Trim().Replace(" ", "_");
            String fileExtension = Path.GetExtension(filename);
            if (fileExtension == ".txt")
            {
                String filepath = Server.MapPath("~/temp/" + filename);
                Fupload.SaveAs(filepath);
                String oriData = File.ReadAllText(filepath);
                System.IO.File.Delete(filepath);
                TxtOriginal.Text  = oriData;
                TxtEncrypted.Text = EncryptData(oriData);
                TxtDecrypt.Text   = DecryptData(TxtEncrypted.Text);

                String savedate  = DateTime.Today.ToString("dd/MM/yyyy");
                String dtime     = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss_tt");
                String dfilename = dtime + "_" + filename;
                Random rnd       = new Random();
                String accesskey = rnd.Next(99999).ToString();
                String userid    = Session["userid"].ToString();

                String dfilepath = Server.MapPath("~/users/" + userid + "/" + dfilename);
                System.IO.File.WriteAllText(dfilepath, TxtEncrypted.Text);

                String fileDescription = TxtFileDescription.Text.ToUpper().Trim();
                string msql            = "insert into filecloud (emailid, filedescription, filename, savedate, savetime, accesskey) values(@emailid, @filedescription, @filename, @savedate, @savetime, @accesskey )";
                GetConnection();
                cmd = new MySqlCommand(msql, con);
                cmd.Parameters.AddWithValue("@emailid", userid);
                cmd.Parameters.AddWithValue("@filedescription", fileDescription);
                cmd.Parameters.AddWithValue("@filename", dfilename);
                cmd.Parameters.AddWithValue("@savedate", savedate);
                cmd.Parameters.AddWithValue("@savetime", dtime);
                cmd.Parameters.AddWithValue("@accesskey", accesskey);
                int n = cmd.ExecuteNonQuery();
                cmd.Dispose();
                CloseConnection();
                if (n == 1)
                {
                    String      emailto   = userid;
                    String      subject   = "Access key of file " + dfilename;
                    String      emailbody = "Dear user " + userid + ", the access key of file " + dfilename + " having description " + fileDescription + " is: " + accesskey;
                    String      from      = "*****@*****.**";
                    String      from_pwd  = "projecttestsipna2017";
                    MailMessage mm        = new MailMessage(from, emailto, subject, emailbody);
                    mm.IsBodyHtml = false;

                    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                    smtp.EnableSsl             = true;
                    smtp.UseDefaultCredentials = true;

                    NetworkCredential netcred = new NetworkCredential(from, from_pwd);
                    smtp.Credentials = netcred;

                    smtp.Send(mm);

                    LblMsg.ForeColor = System.Drawing.Color.Green;
                    LblMsg.Text      = "File saved to cloud..";
                }
                else
                {
                    LblMsg.ForeColor = System.Drawing.Color.Red;
                    LblMsg.Text      = "Unable to save file to cloud..";
                }
            }
            else
            {
                LblMsg.ForeColor = System.Drawing.Color.Red;
                LblMsg.Text      = "Invalid text file..";
            }
        }
        else
        {
            LblMsg.ForeColor = System.Drawing.Color.Red;
            LblMsg.Text      = "Please select a file to upload";
        }// end if hasFile
    }
Ejemplo n.º 2
0
    protected void Btnadd_Click(object sender, EventArgs e)
    {
        string fckstr = Request.Form["textareaItem"].Trim();

        if (Texttitle.Text != "" && fckstr != "")
        {
            if (Request.QueryString["Mcid"] != null)
            {
                string Mcidstr = Request.QueryString["Mcid"].ToString();
                int    Mcid    = Int32.Parse(Mcidstr);
                LearnSite.BLL.Mission  missionbll = new LearnSite.BLL.Mission();
                LearnSite.BLL.ListMenu lbll       = new LearnSite.BLL.ListMenu();
                int    maxSort    = lbll.GetMaxLsort(Mcid) + 1;
                string exampleurl = "~/Statics/cat.sb2";//实例路径
                if (Fupload.HasFile)
                {
                    string sbfilename    = Fupload.FileName;
                    string savePath      = LearnSite.Store.CourseStore.GetSaveUrl("Course", Mcidstr);
                    string shortFileName = Path.GetFileName(sbfilename);
                    string savefilename  = savePath + shortFileName;
                    string sbpath        = this.Server.MapPath(savefilename);
                    Fupload.SaveAs(sbpath);
                    exampleurl = savefilename;
                }

                LearnSite.Model.Mission mission = new LearnSite.Model.Mission();
                mission.Mcid      = Mcid;
                mission.Mtitle    = Texttitle.Text.Trim();
                mission.Msort     = maxSort;
                mission.Mupload   = true;
                mission.Mcategory = 2;//编程页面


                mission.Mexample   = exampleurl;//编程实例
                mission.Microworld = CheckMicoWorld.Checked;
                mission.Mpublish   = CheckPublish.Checked;
                mission.Mcontent   = HttpUtility.HtmlEncode(fckstr);
                mission.Mfiletype  = "sb2";
                mission.Mdate      = DateTime.Now;
                mission.Mhit       = 0;
                mission.Mgroup     = false;
                if (DDLMgid.SelectedValue != "")
                {
                    mission.Mgid = Int32.Parse(DDLMgid.SelectedValue);
                }
                else
                {
                    mission.Mgid = 0;
                }
                int mid = missionbll.Add(mission);
                LearnSite.Model.ListMenu lmodel = new LearnSite.Model.ListMenu();
                lmodel.Lcid   = Mcid;
                lmodel.Lshow  = CheckPublish.Checked;
                lmodel.Lsort  = maxSort;
                lmodel.Ltitle = Texttitle.Text.Trim();
                lmodel.Ltype  = 5;//页面类型为5 编程
                lmodel.Lxid   = mid;
                lbll.Add(lmodel);
                System.Threading.Thread.Sleep(500);
                string url = "~/Teacher/courseshow.aspx?Cid=" + Mcid.ToString();
                Response.Redirect(url, false);
            }
        }
        else
        {
            Labelmsg.Text = "请填写标题或选择实例!";
        }
    }
Ejemplo n.º 3
0
    protected void Btnedit_Click(object sender, EventArgs e)
    {
        string fckstr = mcontent.InnerText;

        if (Texttitle.Text != "" && fckstr != "")
        {
            if (Request.QueryString["Mcid"] != null && Request.QueryString["Mid"] != null)
            {
                string Mcid    = Request.QueryString["Mcid"].ToString();
                string Mid     = Request.QueryString["Mid"].ToString();
                string Example = HlExample.NavigateUrl;
                if (Fupload.HasFile)
                {
                    string savePath      = LearnSite.Store.CourseStore.GetSaveUrl("Course", Mcid);
                    string sbfilename    = Fupload.FileName;
                    string shortFileName = Path.GetFileName(sbfilename);
                    string savefilename  = savePath + shortFileName;
                    string sbpath        = this.Server.MapPath(savefilename);
                    Fupload.SaveAs(sbpath);
                    Example = savefilename;
                }
                LearnSite.Model.Mission mission = new LearnSite.Model.Mission();
                mission.Mid        = Int32.Parse(Mid);
                mission.Mtitle     = Texttitle.Text.Trim();
                mission.Mupload    = true;
                mission.Mcategory  = 2;       //编程页面
                mission.Mexample   = Example; //编程实例
                mission.Microworld = CheckMicoWorld.Checked;
                mission.Mpublish   = CheckPublish.Checked;
                mission.Mcontent   = HttpUtility.HtmlEncode(fckstr);
                mission.Mfiletype  = "sb2";
                mission.Mdate      = DateTime.Now;
                mission.Mhit       = 0;
                mission.Mgroup     = false;
                if (DDLMgid.SelectedValue != "")
                {
                    mission.Mgid = Int32.Parse(DDLMgid.SelectedValue);
                }
                else
                {
                    mission.Mgid = 0;
                }
                LearnSite.BLL.Mission missionbll = new LearnSite.BLL.Mission();
                missionbll.Update(mission);

                LearnSite.Model.ListMenu lmodel = new LearnSite.Model.ListMenu();
                LearnSite.BLL.ListMenu   lbll   = new LearnSite.BLL.ListMenu();

                lmodel.Lcid   = Int32.Parse(Mcid);
                lmodel.Lxid   = Int32.Parse(Mid);
                lmodel.Ltype  = 5;//页面类型为5 编程
                lmodel.Lshow  = CheckPublish.Checked;
                lmodel.Ltitle = Texttitle.Text.Trim();
                lbll.UpdateMenuThree(lmodel);
                System.Threading.Thread.Sleep(500);
                string url = "~/Teacher/programshow.aspx?Mcid=" + Mcid + "&Mid=" + Mid;
                Response.Redirect(url, false);
            }
            else
            {
                Labelmsg.Text = "取不到主题编号Mid!";
            }
        }
        else
        {
            Labelmsg.Text = "内容及标题不能为空!";
        }
    }
    protected void BtnSaveToCloud_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                if (Fupload.HasFile)
                {
                    string filename      = Fupload.FileName.ToLower().Trim().Replace(" ", "_");
                    String fileExtension = Path.GetExtension(filename);
                    if (fileExtension == ".txt" || fileExtension == ".bat" || fileExtension == ".exe" || fileExtension == ".mal" || fileExtension == ".vir" || fileExtension == ".smtmp" || fileExtension == ".buk")
                    {
                        LblMsg.ForeColor = System.Drawing.Color.Red;
                        LblMsg.Text      = "File not allowed to save on cloud..";
                        return;
                    }
                    else
                    {
                        long fileSize = Fupload.PostedFile.ContentLength;
                        if (fileSize > 1073741824) // 1GB
                        {
                            LblMsg.ForeColor = System.Drawing.Color.Red;
                            LblMsg.Text      = "Maximum file size (1GB) exceeded..";
                            return;
                        }
                        else
                        {
                            String userid          = Session["userid"].ToString();
                            String fileDescription = TxtFileDescription.Text.ToUpper().Trim();
                            String savedate        = DateTime.Today.ToString("dd/MM/yyyy");
                            String dtime           = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss_tt");
                            filename = dtime + "_" + filename;
                            Random rnd       = new Random();
                            String accesskey = rnd.Next(99999).ToString();
                            string msql      = "insert into filecloud (emailid, filedescription, filename, savedate, savetime, accesskey) values(@emailid, @filedescription, @filename, @savedate, @savetime, @accesskey )";
                            GetConnection();
                            cmd = new MySqlCommand(msql, con);
                            cmd.Parameters.AddWithValue("@emailid", userid);
                            cmd.Parameters.AddWithValue("@filedescription", fileDescription);
                            cmd.Parameters.AddWithValue("@filename", filename);
                            cmd.Parameters.AddWithValue("@savedate", savedate);
                            cmd.Parameters.AddWithValue("@savetime", dtime);
                            cmd.Parameters.AddWithValue("@accesskey", accesskey);
                            int n = cmd.ExecuteNonQuery();
                            cmd.Dispose();
                            CloseConnection();
                            if (n == 1)
                            {
                                Fupload.SaveAs(Server.MapPath("~/users/" + userid + "/" + filename));
                                String      emailto   = userid;
                                String      subject   = "Access key of file " + filename;
                                String      emailbody = "Dear user " + userid + ", the access key of file " + filename + " having description " + fileDescription + " is: " + accesskey;
                                String      from      = "*****@*****.**";
                                String      from_pwd  = "projecttestsipna2017";
                                MailMessage mm        = new MailMessage(from, emailto, subject, emailbody);
                                mm.IsBodyHtml = false;

                                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                                smtp.EnableSsl             = true;
                                smtp.UseDefaultCredentials = true;

                                NetworkCredential netcred = new NetworkCredential(from, from_pwd);
                                smtp.Credentials = netcred;

                                smtp.Send(mm);

                                LblMsg.ForeColor = System.Drawing.Color.Green;
                                LblMsg.Text      = "File saved to cloud..";
                            }
                            else
                            {
                                LblMsg.ForeColor = System.Drawing.Color.Red;
                                LblMsg.Text      = "Unable to save file to cloud..";
                            }
                        }
                    }
                }
                else
                {
                    LblMsg.ForeColor = System.Drawing.Color.Red;
                    LblMsg.Text      = "Please, select a file";
                }
            }
            catch (Exception ex)
            {
                LblMsg.ForeColor = System.Drawing.Color.Red;
                LblMsg.Text      = ex.Message;
            }
        }
        else
        {
            LblMsg.ForeColor = System.Drawing.Color.Red;
            LblMsg.Text      = "Validation errors..";
        }
    }