/// <summary> /// ��������б� /// </summary> public List<WebProject.Model.BaseData.ZT_COM_RongYu> DataTableToList(DataTable dt) { List<WebProject.Model.BaseData.ZT_COM_RongYu> modelList = new List<WebProject.Model.BaseData.ZT_COM_RongYu>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { WebProject.Model.BaseData.ZT_COM_RongYu model; for (int n = 0; n < rowsCount; n++) { model = new WebProject.Model.BaseData.ZT_COM_RongYu(); if(dt.Rows[n]["RongYuID"].ToString()!="") { model.RongYuID=int.Parse(dt.Rows[n]["RongYuID"].ToString()); } model.Title=dt.Rows[n]["Title"].ToString(); model.ImgUrl=dt.Rows[n]["ImgUrl"].ToString(); model.Body=dt.Rows[n]["Body"].ToString(); model.RongYuTypeName=dt.Rows[n]["RongYuTypeName"].ToString(); model.RongYuTypeNo=dt.Rows[n]["RongYuTypeNo"].ToString(); if(dt.Rows[n]["RongYuOrder"].ToString()!="") { model.RongYuOrder=int.Parse(dt.Rows[n]["RongYuOrder"].ToString()); } model.CreateBy=dt.Rows[n]["CreateBy"].ToString(); if(dt.Rows[n]["CreateDate"].ToString()!="") { model.CreateDate=DateTime.Parse(dt.Rows[n]["CreateDate"].ToString()); } model.LastUpdateBy=dt.Rows[n]["LastUpdateBy"].ToString(); if(dt.Rows[n]["LastUpdateDate"].ToString()!="") { model.LastUpdateDate=DateTime.Parse(dt.Rows[n]["LastUpdateDate"].ToString()); } model.Remark=dt.Rows[n]["Remark"].ToString(); modelList.Add(model); } } return modelList; }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Session["ZT_ADMIN"] == null) { Response.Redirect("Login.aspx"); } else { if (this.txtTitle.Text.Trim() == "") { MessageBox.Show(this, "请输入荣誉标题!"); return; } int RongYuOrder; if (this.txtRongYuOrder.Text.Trim() == "") { RongYuOrder = 1000; } else { double u; if (!double.TryParse(this.txtRongYuOrder.Text.Trim(), out u)) { MessageBox.Show(this, "排序必须为数字!"); return; } else { RongYuOrder = Convert.ToInt32(this.txtRongYuOrder.Text.Trim()); } } if (this.txtBody.Text.Trim() == "") { MessageBox.Show(this, "请输入荣誉内容!"); return; } Boolean fileTypeOK = false; String path = Server.MapPath("~/SysManage/IMG/"); if (txtImgUrl.HasFile == false) { WebProject.Model.BaseData.ZT_COM_RongYu model_RongYu = new WebProject.Model.BaseData.ZT_COM_RongYu(); model_RongYu.Title = this.txtTitle.Text.Trim(); if (this.txtRongYuType.Items.Count > 0) { model_RongYu.RongYuTypeNo = this.txtRongYuType.SelectedValue.ToString(); model_RongYu.RongYuTypeName = this.txtRongYuType.Items[this.txtRongYuType.SelectedIndex].Text.ToString(); } model_RongYu.ImgUrl = "onlinenone.jpg"; model_RongYu.RongYuOrder = Int32.Parse(this.txtRongYuOrder.Text.Trim()); model_RongYu.Body = this.txtBody.Text.Trim(); model_RongYu.CreateBy = SessionUtil.GetAdminSession().AdminNo; model_RongYu.CreateDate = DateTime.Now; WebProject.BLL.BaseData.ZT_COM_RongYu bll_Rongyu = new WebProject.BLL.BaseData.ZT_COM_RongYu(); bll_Rongyu.Add(model_RongYu); MessageBox.ShowAndRedirect(this, "添加信息成功!", "RongYuList.aspx"); } if (txtImgUrl.HasFile == true) { String fileExtension = System.IO.Path.GetExtension(txtImgUrl.FileName).ToLower(); String[] allowedExtensions = { ".bmp", ".jpg", ".jpeg", ".png", ".gif" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileTypeOK = true; break; } } if (fileTypeOK == false) { MessageBox.Show(this, "你要上传的文件类型不符合要求!"); return; } if (fileTypeOK == true) { if (txtImgUrl.PostedFile.ContentLength > 10240000) { MessageBox.Show(this, "你选择上传的文件不能大于10M,请重新选择!"); return; } if (txtImgUrl.PostedFile.ContentLength <= 10240000) { try { string SaveFileName = DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + fileExtension; txtImgUrl.PostedFile.SaveAs(path + SaveFileName); WebProject.Model.BaseData.ZT_COM_RongYu model_RongYu = new WebProject.Model.BaseData.ZT_COM_RongYu(); model_RongYu.Title = this.txtTitle.Text.Trim(); if (this.txtRongYuType.Items.Count > 0) { model_RongYu.RongYuTypeNo = this.txtRongYuType.SelectedValue.ToString(); model_RongYu.RongYuTypeName = this.txtRongYuType.Items[this.txtRongYuType.SelectedIndex].Text.ToString(); } model_RongYu.ImgUrl = SaveFileName; model_RongYu.RongYuOrder = Int32.Parse(this.txtRongYuOrder.Text.Trim()); model_RongYu.Body = this.txtBody.Text.Trim(); model_RongYu.CreateBy = SessionUtil.GetAdminSession().AdminNo; model_RongYu.CreateDate = DateTime.Now; WebProject.BLL.BaseData.ZT_COM_RongYu bll_RongYu = new WebProject.BLL.BaseData.ZT_COM_RongYu(); bll_RongYu.Add(model_RongYu); LogManage.WriteLog(Request.UserHostAddress, "荣誉管理", "添加荣誉", "成功", " 荣誉名称:" + model_RongYu.Title + "操作人:" + SessionUtil.GetAdminSession().AdminNo); MessageBox.ShowAndRedirect(this, "添加信息成功!", "RongYuList.aspx"); } catch (Exception) { MessageBox.Show(this, "文件上传失败!"); return; } } } } } }