⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uckaitibaogao.ascx.cs

📁 在线 图书网上购物系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class UserControls_paper_part_ucKaiTiBaoGao : System.Web.UI.UserControl
{
    private static string StudentID = String.Empty;
    private static object[] TableInfo = new object[7];
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //这个页面学生和教师都可以查看,教师查看时,将先获取StudentID。
            if (!String.IsNullOrEmpty(Request.Params["StudentID"]))
            {
                StudentID = Request["StudentID"].Trim();
            }
            else
            {
                StudentID = Session["LoginID"].ToString();//学生自己查看
            }
         
            DataTable dt = CandidatePaper.GetTeacherStudentPaperInfo(StudentID);//显示上面的个人信息
            if (dt.Rows.Count > 0)
            {
                object[] info = dt.Rows[0].ItemArray;
                this.lbDepartment.Text = info[3].ToString().Trim();
                this.lbStudentName.Text = info[4].ToString().Trim();
                this.lbTeacher.Text = info[0].ToString().Trim();
                this.lbTitle.Text = info[2].ToString().Trim();
                this.lbStudentID.Text = info[6].ToString().Trim();
                this.lbGrade.Text = info[9].ToString().Trim();
                string year = DateTime.Now.Year.ToString();
                this.lbYear.Text = year.Substring(2,2);
                this.lbMonth.Text = DateTime.Now.Month.ToString();
                this.lbDay.Text = DateTime.Now.Day.ToString();
                TableInfo[0] = info[3].ToString().Trim();//depratment
                TableInfo[1] = info[4].ToString().Trim();//studentname
                TableInfo[2] = info[0].ToString().Trim();//teachername
                TableInfo[3] = info[6].ToString().Trim();//studentid
                TableInfo[4] = info[9].ToString().Trim();//grade
                TableInfo[6] = info[2].ToString().Trim();//title
                this.lbMajor.Text = Student.GetMajorNameByStudentID(StudentID);
                TableInfo[5] = this.lbMajor.Text;//major

                LoadData();
            }
            else
            {
                this.lbMsg.Text = "还没有选题,无法查看开题报告!";
                return;
            }
        } 
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        WriteToDoc();
       
    }
    protected void btnDownload_Click(object sender, EventArgs e)
    {
        Response.Redirect("frmDownload.aspx?StudentID='" + StudentID + "'&Name=开题报告");
      
    }

    private void LoadData()
    {
        object optional = System.Reflection.Missing.Value;
        object visible = true;
        object saveChanges = true;
        object NOTsaveChanges = false;
        object docreadonly = true;
        object originalFormat = System.Reflection.Missing.Value;
        object routeDocument = System.Reflection.Missing.Value;
        Word.Document mDoc = null;
        DataTable dt = Global.GetFieldsFromTablesByCondiction("*",
           "View_PaperPartInfo",
           "studentid ='" + StudentID + "' and Name like '开题报告'");
        if (dt.Rows.Count != 0)//已提交过开题报告,则在初使化时显示内容
        {
            string filepath = dt.Rows[0].ItemArray[4].ToString();
            object fullname = Server.MapPath("~/" + filepath);
           // Word.ApplicationClass mWord = new Word.ApplicationClass();
           // mWord.Visible = false;
            MyWord mw = new MyWord();
            try
            {
               if (File.Exists(fullname.ToString()) == true)
                {
                   mw.DotPath = fullname.ToString();
                   mw.OpenFile();
                   this.tbPurport.Text = mw.GetTextInTables(1,1,2);
                   this.tbCurrentResearchInfo.Text = mw.GetTextInTables(1, 2, 2);
                   this.tbMainResearchContext.Text = mw.GetTextInTables(1, 3, 2);
                   this.tbResearchMethod.Text = mw.GetTextInTables(2, 1, 2);
                   this.tbResearchPlan.Text = mw.GetTextInTables(2, 2, 2);
                   this.tbReference.Text = mw.GetTextInTables(2, 3, 2);
                }
                else
                {
                    this.lbMsg.Text = "没有上传开题报告!";
                    return;
                }

            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                mw.Quit();
            }
        }
    }
    private void WriteToDoc()
    {
        string shortdocdir = Global.GeneralizeDocPathByUserID(StudentID);//生成目录,如 Papers/s1
        string docname = Global.GeneralizeFileNameByDate();//2008282921452.doc
        string filepath = shortdocdir + "/" + docname;//相对路径 Papers/s1/200842119350.doc

        string filedir = Server.MapPath("~/" + shortdocdir);//物理路径
        //D:\\My Document\\Visual Studio 2005\\Projects\\POIS\\PaperOnLineInstructionSystem\\Papers\\s1
        DirectoryInfo di = new DirectoryInfo(filedir);
        if (di.Exists == false)
        {
            di.Create();
        }
        MyWord myword = new MyWord();
        myword.DotPath = Server.MapPath("~/dottemplate/开题报告.dot");
        myword.OpenFile();

        object temp = (object)("teachername");
        myword.WriteData(ref temp, TableInfo[2].ToString());
        temp = (object)("department");
        myword.WriteData(ref temp, TableInfo[0].ToString());
        temp = (object)("title");
        myword.WriteData(ref temp, TableInfo[6].ToString());
        temp = (object)("grade");
        myword.WriteData(ref temp, TableInfo[4].ToString());
        temp = (object)("studentname");
        myword.WriteData(ref temp, TableInfo[1].ToString());
        temp = (object)("studentid");
        myword.WriteData(ref temp, TableInfo[3].ToString());
        temp = (object)("major");
        myword.WriteData(ref temp, TableInfo[5].ToString());
        temp = (object)("year");
        string year = DateTime.Now.Year.ToString();
        year = year.Substring(2, 2);
        myword.WriteData(ref temp, year);
        temp = (object)("month");
        myword.WriteData(ref temp, DateTime.Now.Month.ToString());
        temp = (object)("day");
        myword.WriteData(ref temp, DateTime.Now.Day.ToString());


        temp = (object)("purport");
        myword.WriteData(ref temp, this.tbPurport.Text.Trim());

        temp = (object)("currentresearchinfo");
        myword.WriteData(ref temp, this.tbCurrentResearchInfo.Text.Trim());

        temp = (object)("mainresearchcontext");
        myword.WriteData(ref temp, tbMainResearchContext.Text.Trim());

        temp = (object)("researchmethod");
        myword.WriteData(ref temp, tbResearchMethod.Text.Trim());

        temp = (object)("researchplan");
        myword.WriteData(ref temp, this.tbResearchPlan.Text.Trim());

        temp = (object)("reference");
        myword.WriteData(ref temp, this.tbReference.Text.Trim());

       
        object l = (object)(filedir + "/" + docname);//生成文件名。
        myword.SaveAs(ref l);
        myword.Quit();


        //插入记录到数据库
        DataTable dt = Global.GetFieldsFromTablesByCondiction("*",
            "View_PaperPartInfo",
            "studentid ='" + StudentID + "' and Name like '开题报告'");
        if (dt.Rows.Count != 0)//已提交过开题报告,则更新记录
        {
            int paperpartid = int.Parse(dt.Rows[0].ItemArray[11].ToString());
            int candidatepaperid = int.Parse(dt.Rows[0].ItemArray[0].ToString());
            int id = int.Parse(dt.Rows[0].ItemArray[13].ToString());
            Student_Paper_Part spp = Student_Paper_Part.GetStudent_Paper_Part((short)id);
            spp.DocName = docname;
            spp.DocPath = filepath;
            spp.LastModifyDate = System.DateTime.Now;
            if (Student_Paper_Part.Update(spp) != -100)
            {
                File.Delete(Server.MapPath("~/" + dt.Rows[0].ItemArray[4].ToString()));
                this.lbMsg.Text = "更新成功!";
            }
        }
        else//没有提交过,则放入
        {
            Student_Paper_Part spp = new Student_Paper_Part();
            dt = Global.GetFieldsFromTablesByCondiction("CandidatePaperID", "View_StudentTeacherPaper",
                "StudentID='" + StudentID + "'");
            if (dt.Rows.Count == 0)//
            {
                this.lbMsg.Text = "你还没有选题,不能提交";
                return;
            }
            int candidatepaperid = int.Parse(dt.Rows[0].ItemArray[0].ToString());//获得论文id
            dt = Global.GetFieldsFromTablesByCondiction("Paper_PartID", "Paper_Part", " Name like '开题报告'");
            if (dt.Rows.Count == 0)
            {
                this.lbMsg.Text = "操作失败";
                return;
            }
            int paperpartid = int.Parse(dt.Rows[0].ItemArray[0].ToString());//得获TaoBao ID

            spp.CanididatePaperID = candidatepaperid;
            spp.Paper_PartID = (short)paperpartid;
            spp.DocName = docname;
            spp.DocPath = filepath;
            spp.IsTeacherChecked = false;
            spp.IsFinished = false;
            spp.UploadDate = DateTime.Now;
            spp.LastModifyDate = DateTime.Now;
            if (Student_Paper_Part.Insert(spp) != -100)//记录进数据库
            {
                this.lbMsg.Text = "提交成功!";
            }
        }



    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -