//������Ϣ protected void SaveOnClick(object sender, EventArgs e) { if (CodeNumTBX.Text.Trim() == "") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('�������ĺţ�')</script>"); return; } if (TitleTBX.Text.Trim() == "") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('��������⣡')</script>"); return; } if (IsCode(CodeNumTBX.Text.ToString().Trim())) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('�Ѵ��ڸ��ĺźţ����������룡')</script>"); return; } LabMS.Model.Rule rule = new LabMS.Model.Rule(); //LabMS.BLL.Rule ruleinfo = new LabMS.BLL.Rule(); ExtendBLL.Rule ruleinfo = new ExtendBLL.Rule(); rule.Rule_CodeNum = CodeNumTBX.Text;//�ĺ� rule.Rule_Content = LabMS.Common.codehelper.Encode(ResourceContent.Text.Trim());//���� if (ModifyDateTBX.Text != "") { rule.Rule_Date = DateTime.Parse(ModifyDateTBX.Text);//���� } rule.Rule_InputUnit = InputUnitDDL.SelectedValue;//¼�뵥λ rule.Rule_KeyWord = KeyTBX.Text;//�ؼ��� rule.Rule_OutputUnit = OutputUnitTBX.Text.Trim();//���ĵ�λ rule.Rule_SubTitle = SubTitleTBX.Text.Trim();//�ӱ��� rule.Rule_Title = TitleTBX.Text.Trim();//���� rule.Rule_Type = RuleKindDDL.SelectedValue;//���� LabMS.BLL.Attachment att = new LabMS.BLL.Attachment(); LabMS.Model.Attachment attModel = new LabMS.Model.Attachment(); int AttachID=0; if (AttachIDHF.Value != "") { AttachID = int.Parse(AttachIDHF.Value); } HttpFileCollection uploads = HttpContext.Current.Request.Files; if (uploads.Count > 1) { if (AttachIDHF.Value == "") { AttachID = att.Add(attModel); } for (int i = 0; i < uploads.Count; i++) { HttpPostedFile upload = uploads[i]; Random objRand = new Random(); System.DateTime date = DateTime.Now; int fileLength = upload.ContentLength; string filename = upload.FileName; string saveName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + Convert.ToString(objRand.Next(99)) + upload.FileName; if (fileLength == 0) { continue; } //�ж��ļ���С�Ƿ�200K if (fileLength > (2000 * 1024)) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script type='text/javascript'>alert('�ļ���" + filename + ",̫��(���ܳ���2M)��')</script>"); return; } string fileURL = "Content/UploadFile" + "/" + saveName; try { upload.SaveAs(Server.MapPath("../Content/UploadFile") + "/" + saveName); LabMS.BLL.AttachmentItem attIte = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem attIteModel = new LabMS.Model.AttachmentItem(); attIteModel.Attach_ID = AttachID; attIteModel.Item_Address = fileURL; attIteModel.Item_Name = filename; attIte.Add(attIteModel); } catch { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script type='text/javascript'>alert('����ļ�ʧ�ܣ�');</script>"); return; } } } if (AttachID == 0) { rule.AttachmentID = null;//���� } else { rule.AttachmentID = AttachID;//���� } if (ViewState["ID"] != null) { DeleteAttach();//ɾ������ rule.ID = int.Parse(ViewState["ID"].ToString()); ruleinfo.Update(rule); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script type='text/javascript'>alert('������Ϣ�ɹ���');refreshParent();window.close();</script>"); } else { ruleinfo.Add(rule);//���һ������Ϣ Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script type='text/javascript'>alert('������Ϣ�ɹ���');refreshParent();window.location.href='AddRule.aspx';</script>"); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LabMS.Model.Rule GetModel(string Rule_Title,int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,Rule_CodeNum,Rule_Title,Rule_SubTitle,Rule_Content,Rule_Date,Rule_Type,Rule_InputUnit,Rule_OutputUnit,Rule_KeyWord,AttachmentID from Rule "); strSql.Append(" where Rule_Title=@Rule_Title and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@Rule_Title", SqlDbType.VarChar,50), new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = Rule_Title; parameters[1].Value = ID; LabMS.Model.Rule model=new LabMS.Model.Rule(); 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()); } model.Rule_CodeNum=ds.Tables[0].Rows[0]["Rule_CodeNum"].ToString(); model.Rule_Title=ds.Tables[0].Rows[0]["Rule_Title"].ToString(); model.Rule_SubTitle=ds.Tables[0].Rows[0]["Rule_SubTitle"].ToString(); model.Rule_Content=ds.Tables[0].Rows[0]["Rule_Content"].ToString(); if(ds.Tables[0].Rows[0]["Rule_Date"].ToString()!="") { model.Rule_Date=DateTime.Parse(ds.Tables[0].Rows[0]["Rule_Date"].ToString()); } model.Rule_Type=ds.Tables[0].Rows[0]["Rule_Type"].ToString(); model.Rule_InputUnit=ds.Tables[0].Rows[0]["Rule_InputUnit"].ToString(); model.Rule_OutputUnit=ds.Tables[0].Rows[0]["Rule_OutputUnit"].ToString(); model.Rule_KeyWord=ds.Tables[0].Rows[0]["Rule_KeyWord"].ToString(); if(ds.Tables[0].Rows[0]["AttachmentID"].ToString()!="") { model.AttachmentID=int.Parse(ds.Tables[0].Rows[0]["AttachmentID"].ToString()); } return model; } else { return null; } }