📄 ucinstructrecordwrite.ascx.cs
字号:
tbContext.Width = Unit.Pixel(400);
tbContext.Height = Unit.Pixel(50);
tbContext.EnableViewState = true;
LiteralControl lc2 = new LiteralControl("<BR/>");
if (tempPhContext.FindControl("tbContext" + (RowNum + 1).ToString()) == null)
{
tempPhContext.Controls.Add(tbContext);//只是临时显示一下?
tempPhContext.Controls.Add(lc2);
}
phDateTime.Controls.Add(tempPhDate);
phContext.Controls.Add(tempPhContext);
RowNum++;
NameValueCollection requestCollection = Request.Form;
bool flag1 = false;
bool flag2 = false;
if (HT.Contains("tbDate1"))
{
HT.Remove("tbDate1");
}
HT.Add("tbDate1", this.tbDate1.Text.Trim());
if (HT.Contains("tbContext1"))
{
HT.Remove("tbContext1");
}
HT.Add("tbContext1", this.tbContex1.Text.Trim());
for (int j = 2; j < RowNum;j++ )
{
foreach (string key in requestCollection.AllKeys)
{
if (key.IndexOf("tbDate" + j.ToString()) != -1)//找到tbdate*
{
TextBox tb1 = (TextBox)tempPhDate.FindControl("tbDate" + j.ToString());
tb1.Text = requestCollection[key];
if (tb1.Text.Trim() == "")
{
this.lbMsg.Text = "数据不能为空";
return;
}
if (HT.Contains("tbDate" + j.ToString()))
{
HT.Remove("tbDate" + j.ToString());
}
HT.Add("tbDate" + j.ToString(), requestCollection[key]);
flag1 = true;
}
if (key.IndexOf("tbContext" + j.ToString()) != -1)
{
TextBox tb2 = (TextBox)tempPhDate.FindControl("tbContext" + j.ToString());
tb2.Text = requestCollection[key];
if (tb2.Text.Trim() == "")
{
this.lbMsg.Text = "数据不能为空";
return;
}
if (HT.Contains("tbContext" + j.ToString()))
{
HT.Remove("tbContext" + j.ToString());
}
HT.Add("tbContext" + j.ToString(), requestCollection[key]);
flag2 = true;
}
if (flag1 && flag2)
{
//Session["RowNum"] = (int)Session["RowNum"] + 1;
flag1 = false;//只有等两个值都找到之后才能加一
flag2 = false;
break;
}
}
}
}
protected void btnUpLoad_Click(object sender, EventArgs e)
{
phDateTime.Controls.Add(tempPhDate);
phContext.Controls.Add(tempPhContext);
this.btnUpLoad.Enabled = false;
WriteToDoc();
this.btnUpLoad.Enabled = true;
}
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[] marks = myword.GetMark();//取出模板中的标签
object temp = (object)("name");
myword.WriteData(ref temp, TableInfo[2].ToString());
temp = (object)("department");
myword.WriteData(ref temp,TableInfo[0].ToString());
temp = (object)("major");
myword.WriteData(ref temp, TableInfo[6].ToString());
temp = (object)("gxdw");
myword.WriteData(ref temp, TableInfo[4].ToString());
temp = (object)("studentname");
myword.WriteData(ref temp, TableInfo[1].ToString());
temp = (object)("title");
myword.WriteData(ref temp, TableInfo[3].ToString());
temp = (object)("zc");
myword.WriteData(ref temp, TableInfo[5].ToString());
for (int i = 0; i < HT.Count / 2; i++)
{
string t = HT["tbDate" + (i + 1).ToString()].ToString();
string d = HT["tbContext" + (i + 1).ToString()].ToString();
object o = (object)("t" + (i + 1).ToString());
myword.WriteData(ref o, t);//在标签处写数据
o = (object)("d" + (i + 1).ToString());
myword.WriteData(ref o, d);
}
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());
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 btnDownLoad_Click(object sender, EventArgs e)
{
phDateTime.Controls.Add(tempPhDate);
phContext.Controls.Add(tempPhContext);
Response.Redirect("frmDownload.aspx?Studentid='" + StudentID + "'&Name=教师指导记录表");
}
private void SaveContextToFile(string filename)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -