/// <summary> /// 返回一个AttachmentID /// </summary> /// <param></param> /// <returns></returns> protected int AttachmentSave() { int Attach_ID = 0; bool saved=false; if (HttpContext.Current.Request.Files.Count - 1 > 0) { try { int count = HttpContext.Current.Request.Files.Count; HttpFileCollection Files = HttpContext.Current.Request.Files; string savePath = HttpContext.Current.Request.MapPath(@"../Content/UpLoadFile/"); List<string> fileName = LabMS.Common.FileUpload.SaveFiles(Files, savePath); LabMS.BLL.Attachment Attachment = new LabMS.BLL.Attachment(); LabMS.Model.Attachment attachmentmodel = new LabMS.Model.Attachment(); Attach_ID = Attachment.Add(attachmentmodel); if (Attach_ID != 0) { LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem attachmentitemmodel; for (int n = 0; n < fileName.Count; n++) { if (fileName[n].Trim() != "") { attachmentitemmodel = new LabMS.Model.AttachmentItem(); attachmentitemmodel.Attach_ID = Attach_ID; attachmentitemmodel.Item_Address = "Content/UpLoadFile/" + fileName[n].Trim(); attachmentitemmodel.Item_Name = fileName[n].Substring(0, fileName[0].LastIndexOf("_")); attachmentitemmodel.Item_Type = "3"; AttachItem.Add(attachmentitemmodel); } } } saved = true; } catch (Exception ex) { lbErr.Text = ex.Message; } finally { if (saved == false) { } } } return Attach_ID; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Request.QueryString["Flag"] == "download") { if (!IsNumber(Request.QueryString["ID"])) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('查询字符串错误');window.close();</script>"); return; } LabMS.BLL.AttachmentItem attachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem attachmodel = new LabMS.Model.AttachmentItem(); attachmodel = attachItem.GetModel(int.Parse(Request.QueryString["ID"].Trim())); FileItemDownload(attachmodel.ID, attachmodel.Item_Address, attachmodel.Item_Name); return; } else if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Request.QueryString["Flag"] == "attachdownload") { if (!IsNumber(Request.QueryString["ID"])) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('查询字符串错误');window.close();</script>"); return; } LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment(); LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment(); attachmodel = Attach.GetModel(int.Parse(Request.QueryString["ID"].Trim())); FileItemDownload(attachmodel.ID, attachmodel.Attach_Address, attachmodel.Attach_Name); return; } if (!string.IsNullOrEmpty(Request.QueryString["ID"])) { if (!IsNumber(Request.QueryString["ID"])) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('查询字符串错误');window.close();</script>"); return; } LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment(); LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment(); attachmodel = Attach.GetModel(int.Parse(Request.QueryString["ID"].Trim())); Gv_DataBind(attachmodel); } } //if (Request.QueryString["ID"] == null) //{ // Common.JShelper.JSAlert(Page, "err", "参数错误!"); // return; //} //else if (Request.QueryString["ID"] != null && Request.QueryString["type"] == null) //{ // int iTemp = 0; // string strID = Request.QueryString["ID"].ToString(); // if (!int.TryParse(strID, out iTemp)) // { // Common.JShelper.JSAlert(Page, "err", "参数错误!"); // return; // } // LabMS.Model.Attachment mattach = new LabMS.Model.Attachment(); // LabMS.BLL.Attachment battach = new LabMS.BLL.Attachment(); // mattach = battach.GetModel(iTemp); // if (mattach.Attach_Name == "") // { // Response.Redirect("DownloadFile.aspx?ID=" + strID + "&type=1"); // } // else // { // string FullFileName = mattach.Attach_Address; // string FileName = mattach.Attach_Name; // try // { // FullFileName = Server.MapPath("../" + FullFileName); // Context.Response.Buffer = true; // Context.Response.Clear(); // Context.Response.AppendHeader("Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(FullFileName, System.Text.Encoding.UTF8)); // Response.ContentType = "application/x-zip-compressed"; // Response.TransmitFile(FullFileName); // } // catch // { // Common.JShelper.JSAlert(Page, "err", "路径错误!"); // return; // } // Response.End(); // } //} //else if (Request.QueryString["ID"] != null && Request.QueryString["type"] != null) //{ // if (Request.QueryString["type"].ToString().Equals("1")) // { // List<LabMS.Model.AttachmentItem> listattchitem = new List<LabMS.Model.AttachmentItem>(); // LabMS.BLL.AttachmentItem battachitem = new LabMS.BLL.AttachmentItem(); // int iTemp = 0; // string strID = Request.QueryString["ID"].ToString(); // if (!int.TryParse(strID, out iTemp)) // { // Common.JShelper.JSAlert(Page, "err", "参数错误!"); // return; // } // listattchitem = battachitem.GetModelList("Attach_ID = " + strID); // foreach (LabMS.Model.AttachmentItem mai in listattchitem) // { // mai.Item_Address = "<a onclick=foo('DownloadFile.aspx?type=2&ID=" + mai.ID.ToString() + "')>点击下载</a>"; // } // gvFile.DataSource = listattchitem; // gvFile.DataBind(); // gvFile.Visible = true; // } // else if (Request.QueryString["type"].ToString().Equals("2")) // { // int iTemp = 0; // string strID = Request.QueryString["ID"].ToString(); // if (!int.TryParse(strID, out iTemp)) // { // Common.JShelper.JSAlert(Page, "err", "参数错误!"); // return; // } // LabMS.Model.AttachmentItem mattach = new LabMS.Model.AttachmentItem(); // LabMS.BLL.AttachmentItem battach = new LabMS.BLL.AttachmentItem(); // mattach = battach.GetModel(iTemp); // string FullFileName = mattach.Item_Address; // string FileName = mattach.Item_Name; // try // { // FullFileName = Server.MapPath("../" + FullFileName); // Context.Response.Buffer = true; // Context.Response.Clear(); // Context.Response.AppendHeader("Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8)); // Response.ContentType = "application/x-zip-compressed"; // Response.TransmitFile(FullFileName); // } // catch // { // Common.JShelper.JSAlert(Page, "err", "路径错误!"); // return; // } // Response.End(); // } //} }
//������Ϣ 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>"); } }
protected bool SaveItem(LabMS.Model.ProjectApp applicationmodel) { bool save = false; if (applicationmodel != null) { int Attach_ID = 0; if (applicationmodel.App_Attachment == null) { if (HttpContext.Current.Request.Files.Count - 1 > 0) { LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment(); LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment(); applicationmodel.App_Attachment = Attach.Add(attachmodel); } } else { Attach_ID = applicationmodel.App_Attachment.Value; } if (Attach_ID != 0) { //ɾ�� try { LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); List<LabMS.Model.AttachmentItem> ls = new List<LabMS.Model.AttachmentItem>(); ls = AttachItem.GetModelList("Item_Type='1' and Attach_ID=" + Attach_ID); string[] array1 = itemIDs.Value.Split(','); if (array1[0] != "") { for (int i = 0; i < array1.Length; i++) { int itemid = 0; if (int.TryParse(array1[i], out itemid)) { AttachItem.Delete(itemid); } } } } catch(Exception ex) { lb_Error.Text = ex.Message; } //��� if (HttpContext.Current.Request.Files.Count-1 > 0) { try { LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem itemmodel; HttpFileCollection Files = HttpContext.Current.Request.Files; string savePath = Request.MapPath(@"../Content/UpLoadFile/"); List<string> fileNames = LabMS.Common.FileUpload.SaveFiles(Files, savePath); for (int n = 0; n < fileNames.Count; n++) { itemmodel = new LabMS.Model.AttachmentItem(); itemmodel.Item_Address = "Content/UpLoadFile/" + fileNames[n].Trim(); int index = fileNames[n].LastIndexOf("_"); itemmodel.Item_Name = fileNames[n].Substring(0, fileNames[n].LastIndexOf("_")); itemmodel.Attach_ID = Attach_ID; itemmodel.Item_Type = "1"; AttachItem.Add(itemmodel); } save = true; } catch { save = false; } } } } return save; }
private void FileItemDownload(int itemID) { if (itemID == 0) { lb_Error.Text = "������������"; return; } System.IO.Stream iStream = null; try { //�����ļ�ȫ·���� LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem itemmodel = new LabMS.Model.AttachmentItem(); itemmodel = AttachItem.GetModel(itemID); string fullpath = Server.MapPath("../" + itemmodel.Item_Address); string fileName = itemmodel.Item_Name; string NameTemp = ""; if (Request.Browser.Browser == "IE") { NameTemp = HttpUtility.UrlEncode(fileName); NameTemp = NameTemp.Replace("+", "%20"); } else { NameTemp = fileName; NameTemp = NameTemp.Replace(" ", ""); } Response.Clear(); Response.Charset = "UTF-8"; Response.Buffer = true; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.HeaderEncoding = System.Text.Encoding.UTF8; Response.AppendHeader("Content-Disposition", "attachment;filename=" + NameTemp); Response.ContentType = "application/octet-stream"; byte[] buffer = new byte[100000]; int iLength; long dataToRead; iStream = new FileStream(fullpath, FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); dataToRead = iStream.Length; while (dataToRead > 0) { if (Response.IsClientConnected) { iLength = iStream.Read(buffer, 0, 100000); Response.BinaryWrite(buffer); Response.Flush(); buffer = new byte[100000]; dataToRead = dataToRead - iLength; } else { dataToRead = -1; } } } catch (Exception ex) { lb_Error.Text = ex.Message; } finally { if (iStream != null) { iStream.Close(); } } }
protected void btn_AddEval_Click(object sender, EventArgs e) { if (QueryString != HFQueryString || QueryString <= 0) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript' >alert('��ѯ�ַ�������');window.location.href='';</script>"); return; } int ID = QueryString; if (ID > 0) { try { bool save = false; LabMS.BLL.ProjectApp Application = new LabMS.BLL.ProjectApp(); LabMS.Model.ProjectApp model = Application.GetModel(ID); if (model != null) { if (HttpContext.Current.Request.Files.Count - 1 > 0) { int Attach_ID = model.App_Attachment.Value; if (model.App_Attachment == null) { LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment(); LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment(); Attach_ID = Attach.Add(attachmodel); model.App_Attachment = Attach_ID; } else { int count = HttpContext.Current.Request.Files.Count; HttpFileCollection Files = HttpContext.Current.Request.Files; string savePath = HttpContext.Current.Request.MapPath(@"../Content/UpLoadFile/"); List<string> fileNames = LabMS.Common.FileUpload.SaveFiles(Files, savePath); if (Attach_ID != 0) { LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem itemmodel; for (int n = 0; n < fileNames.Count; n++) { if (fileNames[n].Trim() != "") { itemmodel = new LabMS.Model.AttachmentItem(); itemmodel.Item_Address = "Content/UpLoadFile/" + fileNames[n].Trim(); int index = fileNames[n].LastIndexOf("_"); itemmodel.Item_Name = fileNames[n].Substring(0, fileNames[n].LastIndexOf("_")); itemmodel.Attach_ID = Attach_ID; itemmodel.Item_Type = "4"; AttachItem.Add(itemmodel); } } } save = true; } } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript' >alert('�ļ�����Ϊ��');window.location.href='';</script>"); return; } model.App_ExamineView = tb_ExamineView.Text; model.App_State = "Examined"; model.App_AcceptanceTime = DateTime.Now; Application.Update(model); Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript' >if(window.confirm('�Ƿ��б�ҳ��')){window.location.href='AppExaminedList.aspx';}else{window.location.href=window.location.href;}</script>"); return; } } catch { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript' >alert('���ݴ�ȡ����,����ϵ����Ա');window.location.href='';</script>"); return; } } }
//�ύ�½�ʵ�������� protected void Save_OnClick(object sender, EventArgs e) { if (LabNameTBX.Text.Trim() == "") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('������ʵ��������!')</script>"); return; } if (LabNumTBX.Text.Trim() == "") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('������ʵ���ұ��!')</script>"); return; } //�ж��Ƿ��Ѵ��ڸ�ʵ���ұ�� if (IsCode(LabNumTBX.Text.ToString().Trim())) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('�Ѵ��ڸ�ʵ���ұ�ţ����������룡')</script>"); return; } //�ϴ��ļ���ȡ����IDֵ //int id = UpdateFile(); //�ж��Ƿ����� //if (id == -1) //{ // Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('�ϴ�ʧ�ܣ��ϴ����ļ����ܴ���4M��')</script>"); // return; //} //��ȡʵ������Ϣ LabMS.Model.Lab lab = new LabMS.Model.Lab();//����һ��lab���� //if (id != 0) //{ // lab.Lab_Summary = id;//��ȡ���ID //} lab.Lab_Code = LabNumTBX.Text.ToString().Trim();//��ȡʵ���ұ�� lab.Lab_Name = LabNameTBX.Text.ToString().Trim();//��ȡʵ�������� lab.Lab_Category = LabKindDDL.SelectedValue.Trim();//��ȡʵ������� lab.Lab_Level = LabLevelDDL.SelectedValue.Trim();//��ȡʵ���Ҽ��� if (DateTBX.Text.Trim() != "") { lab.Lab_SetupTime = DateTime.Parse(DateTBX.Text.Trim());//��ȡʵ���ҽ������ } lab.Lab_InCharge = ManagerTBX.Text.ToString().Trim();//��ȡʵ���Ҹ����� lab.Lab_Phone = TelTBX.Text.ToString().Trim();//��ȡ��ϵ�绰 lab.Lab_State = StatusDDL.SelectedValue.Trim();//��ȡʹ��״̬ lab.Lab_Curriculum = CurriculumTBX.Text.ToString().Trim();//��ȡ��Ҫ�е��γ� lab.Lab_Type = LabTypeDDL.SelectedValue.Trim();//��ȡʵ�������� lab.Lab_Disciplines = SubjectTBX.Text.Trim();//��ȡ����ѧ�� lab.Lab_AwardLevel = AwardLevelDDL.SelectedValue.Trim();//��ȡ�������� lab.Lab_ApprovalCode = NumTXB.Text.ToString().Trim();//��ȡ���ĺ� lab.Lab_Professional = ProfessionTBX.Text.ToString().Trim();//��ȡ����רҵ lab.Lab_Statement = StatementTBX.Text.Trim();//��ע //��ȡ���м���Ŀ������ if (ProjectNumTBX.Text.ToString().Trim() != "") { int i; if (int.TryParse(ProjectNumTBX.Text.Trim(), out i)) { lab.Lab_ProjectNum = i; } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('���м���Ŀ������ֻ����������!')</script>"); return; } } lab.Lab_Investment = InvestmentTBX.Text.ToString().Trim();//��ȡͶ�ʽ�� //ѧ������ if (AwardNumTBX.Text.ToString().Trim() != "") { int i; if (int.TryParse(AwardNumTBX.Text.Trim(), out i)) { lab.Lab_StAwardNum = i; } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('ѧ������ֻ����������!')</script>"); return; } } //�ϴ����� 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 = 1; 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) //{ // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script type='text/javascript'>alert('�ļ���" + filename + "�ϴ�ʧ�ܣ���Ϊ���ļ�Ϊ���ļ���')</script>"); // continue; //} //�ж��ļ���С�Ƿ�2000K 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) { lab.Lab_Summary = null;//���� } else { lab.Lab_Summary = AttachID;//���� } //�ύ���� if (IDHF.Value != "0") { DeleteAttach();//ɾ������ lab.ID = int.Parse(IDHF.Value); LabMS.BLL.Lab labdata = new LabMS.BLL.Lab(); labdata.Update(lab); Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('���³ɹ���');refreshParent();window.close();</script>"); } else { LabMS.BLL.Lab labdata = new LabMS.BLL.Lab(); labdata.Add(lab); Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('��ӳɹ���');window.location.href='AddNewLab.aspx';</script>"); } }
protected void Submit_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(itemIDs.Value)) { string[] array1 = itemIDs.Value.Split(','); for (int m = 0; m < array1.Length; m++) { if (array1[m] != "0"||array1[m]!="") { LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); AttachItem.Delete(Convert.ToInt32(array1[m])); } } } int attachID = 0; if ((HttpContext.Current.Request.Files.Count - 1) > 0) { bool Result = false; try { LabMS.BLL.ProjectApp Application = new LabMS.BLL.ProjectApp(); LabMS.Model.ProjectApp model = new LabMS.Model.ProjectApp(); model = Application.GetModel(QueryString); if (model.App_Attachment == null) { attachID = 0; } else { attachID = model.App_Attachment.Value; } int count = HttpContext.Current.Request.Files.Count; HttpFileCollection Files = HttpContext.Current.Request.Files; string savePath = HttpContext.Current.Request.MapPath(@"../Content/UpLoadFile/"); List<string> fileNames = LabMS.Common.FileUpload.SaveFiles(Files, savePath); if (attachID == 0) { LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment(); LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment(); attachID = Attach.Add(attachmodel); model.App_Attachment = attachID; } LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem itemmodel; for (int n = 0; n < fileNames.Count; n++) { if (fileNames[n].Trim() != "") { itemmodel = new LabMS.Model.AttachmentItem(); itemmodel.Item_Address = "Content/UpLoadFile/" + fileNames[n].Trim(); itemmodel.Item_Name = fileNames[n].Substring(0, fileNames[n].LastIndexOf("_")); itemmodel.Attach_ID = attachID; itemmodel.Item_Type = "2"; AttachItem.Add(itemmodel); } } Result = true; Application.Update(model); } catch { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�ϴ��ļ�ʱ��������ϵ����Ա��');window.location.href=window.location.href; </script>"); return; } if (Result) { Build.Visible = true; } } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('û�������飬��ѡ����������ϴ���'); </script>"); return; } Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>if(window.confirm('���������ɹ����Ƿ��б�')){ window.location.href='AppTaskList.aspx';}else{window.location.href=window.location.href;}</script>"); return; }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LabMS.Model.AttachmentItem GetModel(int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,Item_Address,Attach_ID,Item_Name,Item_Type from AttachmentItem "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; LabMS.Model.AttachmentItem model=new LabMS.Model.AttachmentItem(); 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.Item_Address=ds.Tables[0].Rows[0]["Item_Address"].ToString(); if(ds.Tables[0].Rows[0]["Attach_ID"].ToString()!="") { model.Attach_ID=int.Parse(ds.Tables[0].Rows[0]["Attach_ID"].ToString()); } model.Item_Name=ds.Tables[0].Rows[0]["Item_Name"].ToString(); model.Item_Type=ds.Tables[0].Rows[0]["Item_Type"].ToString(); return model; } else { return null; } }
protected void Submit_Click(object sender, EventArgs e) { #region Validation if (string.IsNullOrEmpty(App_ProjectCode.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "����д��Ŀ���"); return; } if (string.IsNullOrEmpty(App_Code.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "����д��Ŀ����"); return; } if (App_LabName.SelectedValue.Trim() == "0") { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "ѡ��ʵ���Ҳ���Ϊ��"); return; } if (App_LabType.SelectedValue == "0") { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "��Ŀ��ʵ�������Ͳ���Ϊ��"); return; } if (App_ConstructionType.SelectedValue == "0") { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "��Ŀ�Ľ������Ͳ���Ϊ��"); return; } if (string.IsNullOrEmpty(App_AppTime.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "����ӵ�����ʱ�䲻��Ϊ��"); return; } if (string.IsNullOrEmpty(App_CompletionTime.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "����ӵ����ʱ�䲻��Ϊ��"); return; } if (string.IsNullOrEmpty(App_InCharge.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "��Ŀ�����˲���Ϊ��"); return; } else { if (System.Text.Encoding.Default.GetByteCount(App_InCharge.Text) > 50 ) { LabMS.Common.JShelper.JSAlert(this, "�������ݳ��ȴ���", "��Ŀ�������������Ȳ�����25�����֣�50��Ӣ���ַ�"); } } if (string.IsNullOrEmpty(App_Phone.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������ݴ���", "��ϵ�绰����Ϊ��"); return; } if (string.IsNullOrEmpty(App_ApplyFinancing.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "��Ҫ��������", "����д�������ʽ���Ϊ��"); return; } if (HttpContext.Current.Request.Files.Count - 1 <= 0) { LabMS.Common.JShelper.JSAlert(this, "��Ҫ������", "���ϴ������鸽��"); } int Index = int.Parse(tb_EIndex.Value); decimal tempde=0.0M; int temp=0; for (int i = 0; i < Index; i++) { if (!string.IsNullOrEmpty(Request.Form["code" + i+""]) && !string.IsNullOrEmpty(Request.Form["name" + i+""])) { if (string.IsNullOrEmpty(Request.Form["num" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "���������������ܿ�"); return; } else { if (!int.TryParse(Request.Form["num" + i], out temp)) { LabMS.Common.JShelper.JSAlert(this, "error", "����������������Ϊ����"); return; } } if (string.IsNullOrEmpty(Request.Form["unitprice" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "�����������۲���Ϊ�գ�Ӧ��Ϊ������С��"); return; } else { if (!decimal.TryParse(Request.Form["unitprice" + i], out tempde)) { LabMS.Common.JShelper.JSAlert(this, "error", "������������Ӧ��Ϊ������С����"); return; } } } } #endregion Validation LabMS.BLL.ProjectApp ProjectApp = new LabMS.BLL.ProjectApp(); LabMS.Model.ProjectApp model = new LabMS.Model.ProjectApp(); model.App_Code = App_Code.Text; string[] DateTimeList = { "yyyy/M/d tt hh:mm:ss", "yyyy/MM/dd tt hh:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy/M/d HH:mm:ss", "yyyy/MM/dd", "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd", "yyyy-M-d" }; try { DateTime AppTime = DateTime.ParseExact(App_AppTime.Text, DateTimeList, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite); DateTime CompleteTime=DateTime.ParseExact(App_CompletionTime.Text, DateTimeList, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite); if (DateTime.Compare(AppTime, CompleteTime) <= 0) { model.App_AppTime = AppTime; model.App_CompletionTime = CompleteTime; } else { LabMS.Common.JShelper.JSAlert(this, "����ʱ���С����", "����ϸ�˶ԣ������ʱ��ʹ�С"); return; } } catch { LabMS.Common.JShelper.JSAlert(this, "����ʱ���ʽ����", "����ʱ���ʽ��������������"); return; } model.App_InCharge = App_InCharge.Text; model.App_Phone = App_Phone.Text; model.App_Location = App_Loction.Text.TrimEnd(); model.App_InstallCondition = App_InstallCondition.Text.TrimEnd(); model.App_Necessity = App_Necessity.Text.TrimEnd(); model.App_LabType = App_LabType.SelectedValue; model.App_ConstructionType = App_ConstructionType.SelectedValue; model.App_State = "SubmitNotYet"; model.LabID = Convert.ToInt32(App_LabName.SelectedValue.Trim()); model.App_Positions = tb_PositonCode.Text.Trim(); model.App_ApplyFinancing = Convert.ToInt32(App_ApplyFinancing.Text); model.App_ProjectCode = App_ProjectCode.Text.Trim(); int attachID=0; bool saved = false; if ((HttpContext.Current.Request.Files.Count-1)>0) { try { int count = HttpContext.Current.Request.Files.Count; HttpFileCollection Files = HttpContext.Current.Request.Files; string savePath = HttpContext.Current.Request.MapPath(@"../Content/UpLoadFile/"); List<string> fileNames = LabMS.Common.FileUpload.SaveFiles(Files, savePath); LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment(); LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment(); attachID = Attach.Add(attachmodel); if (attachID != 0) { LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem(); LabMS.Model.AttachmentItem itemmodel; for (int n = 0; n < fileNames.Count; n++) { if (fileNames[n].Trim() != "") { itemmodel = new LabMS.Model.AttachmentItem(); itemmodel.Item_Address = "Content/UpLoadFile/"+fileNames[n].Trim(); int index = fileNames[n].LastIndexOf("_"); itemmodel.Item_Name = fileNames[n].Substring(0, fileNames[n].LastIndexOf("_")); itemmodel.Attach_ID = attachID; itemmodel.Item_Type = "1"; AttachItem.Add(itemmodel); } } } saved = true; } catch { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�ϴ��ļ�ʱ��������ϵ����Ա��');window.location.href='ApplicationList.aspx'; </script>"); return; } } if (saved) { model.App_Attachment = attachID; } int appid = ProjectApp.Add(model); LabMS.Model.ConsumeApp consumeappmodel; LabMS.BLL.ConsumeApp ConsumeApp = new LabMS.BLL.ConsumeApp(); for (int i = 0; i < Index; i++) { consumeappmodel = new LabMS.Model.ConsumeApp(); int nums = 0; decimal unitprice = new decimal(); try { if (!string.IsNullOrEmpty(Request.Form["code" + i.ToString()+""]) ) { consumeappmodel.EquipType = Request.Form["code" + i]; consumeappmodel.EquipName = Request.Form["name" + i]; consumeappmodel.Model = Request.Form["model" + i]; consumeappmodel.Factory = Request.Form["factory" + i]; consumeappmodel.Argument = Request.Form["argument" + i]; decimal.TryParse(Request.Form["unitprice" + i], out unitprice); consumeappmodel.UnitPrice = unitprice; int.TryParse(Request.Form["num" + i], out nums); consumeappmodel.EquipNum = nums; consumeappmodel.AppID = appid; ConsumeApp.Add(consumeappmodel); } } catch (Exception ex) { LabMS.Common.JShelper.JSAlert(this, "header", ex.Message); return; } } Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('��������Ŀ�б�ҳ�棡');window.location.href='ApplicationList.aspx'; </script>"); return; }