📄 uckaitibaogaomeetingreport.ascx.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_ucKaiTiBaoGaoMeetingReport : System.Web.UI.UserControl
{
private static string TeacherID = "";
private static string StudentID = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!String.IsNullOrEmpty(Request.Params["StudentID"]))
{
StudentID = Request["StudentID"].Trim();
}
else
{
StudentID = "s1";//test
}
//TeacherID = Session["LoginID"].ToString();
TeacherID = "t2";
LoadData();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
WriteToDoc();
}
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)//已提交过,则在初使化时显示内容
{
//btnSubmit.Attributes.Add("onclientclick","return(confirm('此次提交将会覆盖前次的数据,确定提交吗?'))");
string filepath = dt.Rows[0].ItemArray[4].ToString();
object fullname = Server.MapPath("~/" + filepath);
MyWord mw = new MyWord();
try
{
if (File.Exists(fullname.ToString()) == true)
{
mw.DotPath = fullname.ToString();
mw.OpenFile();
Word.Tables tbs = mw.GetTablesInDoc();
tbDateTime.Text = mw.GetTextInTables(1,3);
tbLocation.Text = mw.GetTextInTables(1, 5);
tbZCR.Text = mw.GetTextInTables(1, 7);
tbName1.Text = mw.GetTextInTables(1, 13);
tbName2.Text = mw.GetTextInTables(1, 15);
tbName3.Text = mw.GetTextInTables(1, 17);
tbName4.Text = mw.GetTextInTables(1, 19);
tbName5.Text = mw.GetTextInTables(1, 21);
tbName6.Text = mw.GetTextInTables(1, 23);
tbZC1.Text = mw.GetTextInTables(1, 14);
tbZC2.Text = mw.GetTextInTables(1, 16);
tbZC3.Text = mw.GetTextInTables(1, 18);
tbZC4.Text = mw.GetTextInTables(1, 20);
tbZC5.Text = mw.GetTextInTables(1, 22);
tbZC6.Text = mw.GetTextInTables(1, 24);
string temp = mw.GetTextInTables(1, 26);
int index = temp.LastIndexOf("记录人");
tbRecord.Text = temp.Substring(0,index );
tbRecoder.Text = temp.Substring(index + 4);
temp = mw.GetTextInTables(1,28);
index = temp.LastIndexOf("签名");
tbYJ.Text = temp.Substring(0, index);
temp = temp.Substring(index + 3);//temp : 签名:** 2008年08月09日
int year = temp.LastIndexOf("年");
int month = temp.LastIndexOf("月");
tbYear.Text = temp.Substring(year-5,4);
tbMonth.Text = temp.Substring(year+1,2);
tbDay.Text = temp.Substring(month+1,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();
}
string msg = String.Empty;
MyWord myword = new MyWord();
myword.DotPath = Server.MapPath("~/dottemplate/开题报告会议纪要.dot");
myword.OpenFile();
if (tbDateTime.Text == "")
{
msg += "时间不能不空.";
}
else
{
myword.WriteData("datetime", this.tbDateTime.Text);
}
myword.WriteData("address",tbLocation.Text);
myword.WriteData("zcr", tbZCR.Text);
myword.WriteData("name1",tbName1.Text);
myword.WriteData("name2", tbName2.Text);
myword.WriteData("name3", tbName3.Text);
myword.WriteData("name4", tbName4.Text);
myword.WriteData("name5", tbName5.Text);
myword.WriteData("name6", tbName6.Text);
myword.WriteData("zc1", tbZC1.Text);
myword.WriteData("zc2", tbZC2.Text);
myword.WriteData("zc3", tbZC3.Text);
myword.WriteData("zc4", tbZC4.Text);
myword.WriteData("zc5", tbZC5.Text);
myword.WriteData("zc6", tbZC6.Text);
myword.WriteData("record",tbRecord.Text);
myword.WriteData("jlr", tbRecoder.Text);
myword.WriteData("yj",tbYJ.Text);
myword.WriteData("year",tbYear.Text);
myword.WriteData("month",tbMonth.Text.PadLeft(2,'0') );
myword.WriteData("day", tbDay.Text.PadLeft(2, '0'));
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 + "' and TeacherID='" + TeacherID + "'");
if (dt.Rows.Count == 0)
{
this.lbMsg.Text = "提交失败";
return;
}
int candidatepaperid = int.Parse(dt.Rows[0].ItemArray[0].ToString());
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());
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 = "提交成功!";
}
}
}
protected void tbRecord_TextChanged(object sender, EventArgs e)
{
}
protected void btnDownLoad_Click(object sender, EventArgs e)
{
Response.Redirect("~/frmDownload.aspx?StudentID='" + StudentID + "'&Name=开题报告会议纪要");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -