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

📄 ucinstructrecordwrite.ascx.cs

📁 在线 图书网上购物系统
💻 CS
📖 第 1 页 / 共 2 页
字号:

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.Collections.Specialized;
using System.IO;
using System.Data.Common;
using Word;

public partial class UserControls_ucInstructRecordWrite : System.Web.UI.UserControl
{
    private static PlaceHolder tempPhDate = new PlaceHolder();
    private static PlaceHolder tempPhContext = new PlaceHolder();
    private static Hashtable HT = new Hashtable();
    private static int j = 1;
    private static ArrayList alRecord = new ArrayList();
    private static int RowNum = 1;
    private static object[] TableInfo = new object[7];
    private static string StudentID = "";
   
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            if (!String.IsNullOrEmpty(Request.Params["StudentID"]))//教师也可以查看,教师查看时,将设置StudentID。
            {
                StudentID = Request["StudentID"].Trim();
            }
            else
            {
                StudentID = Session["LoginID"].ToString();
            }
            //Session["RowNum"] = 2;
            RowNum = 1;
            tempPhDate.EnableViewState = true;
            tempPhDate.ID = "ph1";
            tempPhContext.EnableViewState = true;
            tempPhContext.ID = "ph2";
            this.lbMsg.Text = "建议不要超过30行数据!";

            string 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.lbMajor.Text = info[4].ToString().Trim();
                this.lbStudnetName.Text = info[4].ToString().Trim();
                this.lbTeacherName.Text = info[0].ToString().Trim();
                this.lbTitle.Text = info[2].ToString().Trim();
                this.lbWorkDept.Text = info[3].ToString().Trim();
                this.lbZC.Text = info[1].ToString().Trim();

                TableInfo[0] = info[3].ToString().Trim();
                TableInfo[1] = info[4].ToString().Trim();
                TableInfo[2] = info[0].ToString().Trim();
                TableInfo[3] = info[2].ToString().Trim();
                TableInfo[4] = info[3].ToString().Trim();
                TableInfo[5] = info[1].ToString().Trim();
            }
            else
            {
                this.lbMsg.Text = "还没有选题,无法查看和编辑教师指导记录表!";
                return;
            }
           
            this.lbMajor.Text = Student.GetMajorNameByStudentID(StudentID);
            TableInfo[6] = this.lbMajor.Text;

            LoadData();//加载文档中的数据
        } 
       
    }
    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);
             MyWord mw = new MyWord();
            try
            {
               
                mw.DotPath = fullname.ToString();
                mw.OpenFile();
                Word.Tables tables = mw.GetTablesInDoc();

                    HT.Clear();
                    phContext.Controls.Clear();
                    phDateTime.Controls.Clear();
                    tempPhDate.Controls.Clear();
                    tempPhContext.Controls.Clear();

                   int Tablerow = tables[1].Rows.Count;
                    tbDate1.Text = mw.GetTextInTables(1,5,1);
                    tbContex1.Text = mw.GetTextInTables(1,5,2);

                    HT.Add("tbDate1", tbDate1.Text);
                    HT.Add("tbContext1", tbContex1.Text);//写入内容的第一行,因为这一行的数据不是动态生成的,
                    int flag = 0;
                    //故要特殊处理
                    for (int i = 2; i <= Tablerow; i++)
                    {

                        string t = mw.GetTextInTables(1, i + 4, 1);//tables[1].Rows[i + 4].Cells[1].Range.Text.Trim();//第六行以后都是自动生成的
                        string d = mw.GetTextInTables(1, i + 4, 2);// tables[1].Rows[i + 4].Cells[2].Range.Text.Trim();
                        if (t.IndexOf("指导时间") != -1 || d.IndexOf("指 导 内 容") != -1)
                        {
                            flag = -1;
                            continue;
                        }
                        if (t == "" && d == "")//内容结束
                            return;

                        RowNum++;//指实际的行数,包括第一行不是自动生成的。

                        LiteralControl lc = new LiteralControl("<BR/>");//加入换行
                        this.lbMsg.Text = "建议不要超过30行数据!";

                        TextBox tbDate = new TextBox();
                        tbDate.ID = "tbDate" + (i + flag).ToString();
                        tbDate.TextMode = TextBoxMode.SingleLine;
                        tbDate.Width = Unit.Pixel(100);
                        tbDate.Height = Unit.Pixel(50);
                        tbDate.EnableViewState = true;
                        tbDate.AutoPostBack = false;
                        tbDate.Text = t;//t.Substring(0, t.LastIndexOf('\r'));

                        tempPhDate.Controls.Add(tbDate);
                        tempPhDate.Controls.Add(lc);

                        TextBox tbContext = new TextBox();
                        tbContext.ID = "tbContext" + (i + flag).ToString();//因为可能跳过了一行,所以应该在将i记数减一
                        tbContext.TextMode = TextBoxMode.MultiLine;
                        tbContext.Width = Unit.Pixel(400);
                        tbContext.Height = Unit.Pixel(50);
                        tbContext.EnableViewState = true;
                        tbContext.Text = d;//t.Substring(0, t.LastIndexOf('\r')); ;


                        HT.Add("tbDate" + (i + flag).ToString(), tbDate.Text);
                        HT.Add("tbContext" + (i + flag).ToString(), tbContext.Text);


                        LiteralControl lc2 = new LiteralControl("<BR/>");

                        tempPhContext.Controls.Add(tbContext);//只是临时显示一下?
                        tempPhContext.Controls.Add(lc2);

                        phDateTime.Controls.Add(tempPhDate);
                        phContext.Controls.Add(tempPhContext);
                    }
                

            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
               mw.Quit();
            }
        }
    }
    protected void btnAddTextBoxs_Click(object sender, EventArgs e)
    {
        LiteralControl lc = new LiteralControl("<BR/>");
        this.lbMsg.Text = "建议不要超过30行数据!";
        //int rowNum = (int)Session["RowNum"];
        if (RowNum >= 30)
        {
            this.lbMsg.Text = "最好不要超过30行数据!";
            return;
        }

        TextBox tbDate = new TextBox();
        tbDate.ID = "tbDate" + (RowNum+1).ToString();//RowNum从1开始
        tbDate.TextMode = TextBoxMode.SingleLine;
        tbDate.Width = Unit.Pixel(100);
        tbDate.Height = Unit.Pixel(50);
        tbDate.EnableViewState = true;
        tbDate.AutoPostBack = false;

        if (tempPhDate.FindControl("tbDate" + (RowNum + 1).ToString()) == null)
        {
            tempPhDate.Controls.Add(tbDate);
            tempPhDate.Controls.Add(lc);
        }

        TextBox tbContext = new TextBox();
        tbContext.ID = "tbContext" + (RowNum + 1).ToString();
        tbContext.TextMode = TextBoxMode.MultiLine;

⌨️ 快捷键说明

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