/// <summary> /// �ύ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Submit_Click(object sender, EventArgs e) { try { #region validate if (string.IsNullOrEmpty(ResourceTitle.Text.Trim())) { WriteBackScript("alert('��Դ���ⲻ��Ϊ��')"); return; } else if (ResourceTitle.Text.Length > 50) { WriteBackScript("alert('��Դ���ⳤ�Ȳ��ܳ���50')"); return; } if (string.IsNullOrEmpty(ResourceContent.Text)) { WriteBackScript("alert('��Դ���ݲ���Ϊ��')"); return; } #endregion Model.Resource resourceInfo = new LabMS.Model.Resource(); ExtendBLL.Resource resource = new ExtendBLL.Resource(); resourceInfo.ResourceTitle = ResourceTitle.Text; resourceInfo.ResourceContent = Server.HtmlEncode(ResourceContent.Text); resourceInfo.ResourceRecordTime = DateTime.Now; resourceInfo.ResourceVisitTime = 0; resourceInfo.RecorderType = Base.PrivilegeManager.GetUserTypeCode(); resourceInfo.ResourceRecorder = int.Parse(UserID); resourceInfo.LabID = int.Parse(ResourceLab.SelectedValue); resourceInfo.ResourceType = 1; // TBD string[] tags = ResourceTags.Text.Split(',', '��'); #region Upload file if (ResourceAttachment.HasFile) { resourceInfo.ResourceAttachmentPath = "Attachment/" + Guid.NewGuid().ToString() + "." + ExtendBLL.FileUtility.GetFileExtension(ResourceAttachment.FileName); ResourceAttachment.PostedFile.SaveAs(Server.MapPath(resourceInfo.ResourceAttachmentPath)); } #endregion resource.Add(resourceInfo, tags); WriteBackScript("alert('�����Դ�ɹ�');window.location.href='List.aspx'"); } catch (Exception ex) { } }
/// <summary> /// ��ȡ���µ���Դ /// </summary> /// <param name="counts">����</param> /// <returns></returns> public List<LabMS.Model.Resource> GetLatest(int counts) { StringBuilder sb = new StringBuilder(); sb.Append("select top "); sb.Append(counts); sb.Append(" [id],ResourceType,LabID,ResourceTitle,ResourceContent,ResourceAttachmentPath,ResourceRecordTime,ResourceRecorder,ResourceVisitTime, ResourceRecorderType from Resource "); sb.Append(" order by [id] desc "); LabMS.Model.Resource model; List<LabMS.Model.Resource> results = new List<LabMS.Model.Resource>(); System.Data.DataSet ds = Maticsoft.DBUtility.DbHelperSQL.Query(sb.ToString()); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { model = new LabMS.Model.Resource(); if (row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["ResourceType"].ToString() != "") { model.ResourceType = int.Parse(row["ResourceType"].ToString()); } if (row["LabID"].ToString() != "") { model.LabID = int.Parse(row["LabID"].ToString()); } model.ResourceTitle = row["ResourceTitle"].ToString(); model.ResourceContent = row["ResourceContent"].ToString(); model.ResourceAttachmentPath = row["ResourceAttachmentPath"].ToString(); if (row["ResourceRecordTime"].ToString() != "") { model.ResourceRecordTime = DateTime.Parse(row["ResourceRecordTime"].ToString()); } if (row["ResourceRecorder"].ToString() != "") { model.ResourceRecorder = int.Parse(row["ResourceRecorder"].ToString()); } if (row["ResourceVisitTime"].ToString() != "") { model.ResourceVisitTime = int.Parse(row["ResourceVisitTime"].ToString()); } model.RecorderType = int.Parse(row["ResourceRecorderType"].ToString()); results.Add(model); } return results; }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LabMS.Model.Resource GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,ResourceType,LabID,ResourceTitle,ResourceContent,ResourceAttachmentPath,ResourceRecordTime,ResourceRecorder,ResourceVisitTime, ResourceRecorderType from Resource "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; LabMS.Model.Resource model = new LabMS.Model.Resource(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["ResourceType"].ToString() != "") { model.ResourceType = int.Parse(ds.Tables[0].Rows[0]["ResourceType"].ToString()); } if (ds.Tables[0].Rows[0]["LabID"].ToString() != "") { model.LabID = int.Parse(ds.Tables[0].Rows[0]["LabID"].ToString()); } model.ResourceTitle = ds.Tables[0].Rows[0]["ResourceTitle"].ToString(); model.ResourceContent = ds.Tables[0].Rows[0]["ResourceContent"].ToString(); model.ResourceAttachmentPath = ds.Tables[0].Rows[0]["ResourceAttachmentPath"].ToString(); if (ds.Tables[0].Rows[0]["ResourceRecordTime"].ToString() != "") { model.ResourceRecordTime = DateTime.Parse(ds.Tables[0].Rows[0]["ResourceRecordTime"].ToString()); } if (ds.Tables[0].Rows[0]["ResourceRecorder"].ToString() != "") { model.ResourceRecorder = int.Parse(ds.Tables[0].Rows[0]["ResourceRecorder"].ToString()); } if (ds.Tables[0].Rows[0]["ResourceVisitTime"].ToString() != "") { model.ResourceVisitTime = int.Parse(ds.Tables[0].Rows[0]["ResourceVisitTime"].ToString()); } model.RecorderType = int.Parse(ds.Tables[0].Rows[0]["ResourceRecorderType"].ToString()); return model; } else { return null; } }