/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Video DataRowToModel(DataRow row) { Maticsoft.Model.Video model=new Maticsoft.Model.Video(); if (row != null) { if(row["ID"]!=null && row["ID"].ToString()!="") { model.ID=int.Parse(row["ID"].ToString()); } if(row["VideoName"]!=null) { model.VideoName=row["VideoName"].ToString(); } if(row["VideoUrl"]!=null) { model.VideoUrl=row["VideoUrl"].ToString(); } if(row["AddUser"]!=null) { model.AddUser=row["AddUser"].ToString(); } if(row["AddTime"]!=null && row["AddTime"].ToString()!="") { model.AddTime=DateTime.Parse(row["AddTime"].ToString()); } } return model; }
private void btnSave_Click(object sender, EventArgs e) { if (txtVideoUrlF.Text.Length > 0) { if (common.videomode == "update") { try { Maticsoft.Model.Video model = bll.GetModel(int.Parse(common.videoid)); Maticsoft.Model.Picture picturemodel = picturebll.GetModelList("PicType='视频' and Belong='" + model.VideoName + "'")[0]; model.AddTime = DateTime.Now; model.AddUser = common.loginuser; model.VideoName = txtVideoName.Text; model.VideoUrl = txtVideoUrlF.Text; picturemodel.PicUrl = txtVideoImg.Text; bll.Update(model); picturebll.Update(picturemodel); MessageBox.Show("保存成功"); } catch { MessageBox.Show("保存失败"); } } else { try { Maticsoft.Model.Video model = new Maticsoft.Model.Video(); Maticsoft.Model.Picture picturemodel = new Maticsoft.Model.Picture(); model.AddTime = DateTime.Now; model.AddUser = common.loginuser; model.VideoName = txtVideoName.Text; model.VideoUrl = txtVideoUrlF.Text; picturemodel.PicUrl = txtVideoUrl.Text; picturemodel.PicType = "视频"; picturemodel.Belong = txtVideoName.Text; bll.Add(model); picturebll.Add(picturemodel); MessageBox.Show("保存成功"); } catch { MessageBox.Show("保存失败"); } } } else { MessageBox.Show("请输入内容"); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Video GetModel(int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,VideoName,VideoUrl,AddUser,AddTime from Video "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = ID; Maticsoft.Model.Video model=new Maticsoft.Model.Video(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }