protected void Save_Click(object sender, EventArgs e) { #region validation int Index = 0; int NewIndex = 0; if (!int.TryParse(tb_EIndex.Value, out Index)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�������ݴ���');window.location.href='ProjectList.aspx';</script>"); return; } if (!int.TryParse(tb_ConsumpIndex.Value, out NewIndex)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�������ݴ���');window.location.href='ProjectList.aspx';</script>"); return; } 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["model" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "�������ͺŲ���Ϊ��"); return; } if (string.IsNullOrEmpty(Request.Form["categorycode" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "��������Ų���Ϊ��"); return; } } } for (int j = 0; j < NewIndex; j++) { if (!string.IsNullOrEmpty(Request.Form["code" + j]) && !string.IsNullOrEmpty(Request.Form["name" + j])) { if (string.IsNullOrEmpty(Request.Form["model" + j])) { LabMS.Common.JShelper.JSAlert(this, "error", "�����ͺŲ���Ϊ��"); return; } if (string.IsNullOrEmpty(Request.Form["categorycode" + j])) { LabMS.Common.JShelper.JSAlert(this, "error", "��������Ų���Ϊ��"); return; } } } #endregion validation 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" }; LabMS.BLL.Project Project = new LabMS.BLL.Project(); LabMS.Model.Project ProjectItem = new LabMS.Model.Project(); ProjectItem = Project.GetModel(Convert.ToInt32(Request.QueryString["ID"].ToString())); ProjectItem.Project_Code = tb_Code.Text.Trim(); ProjectItem.Project_Name = tb_Name.Text.Trim(); ProjectItem.Project_StartTime = DateTime.ParseExact(tb_StartTime.Text.Trim(), DateTimeList, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite); ProjectItem.Project_StartWeek = new int?(Convert.ToInt32(tb_StartWeek.Text.Trim())); ProjectItem.Project_SubmitTime = DateTime.Now; ProjectItem.Project_EndTime = DateTime.ParseExact(tb_EndTime.Text.Trim(), DateTimeList, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite); ProjectItem.Project_EndWeek = new int?(Convert.ToInt32(tb_EndWeek.Text.Trim())); ProjectItem.Project_ClassHourse = new int?(Convert.ToInt32(tb_ClassHourse.Text.Trim())); ProjectItem.Project_Consume = new int?(Convert.ToInt32(tb_Cunsume.Text.Trim())); ProjectItem.Project_PartnerNum = Convert.ToInt32(tb_PatnerNum.Text.Trim()); ProjectItem.Project_Content = tb_Content.Text.TrimEnd(); ProjectItem.Project_Lab = new int?(Convert.ToInt32(ddl_Lab.SelectedValue)); //ProjectItem.Project_PartnerTeamNum = Convert.ToInt32(tb_PatnerTeamNum.Text); ProjectItem.Project_ExpHouse = Convert.ToInt32(tb_ExpHouse.Text.Trim()); ProjectItem.Project_Professional = Convert.ToInt32(ddl_Profess.SelectedValue); ProjectItem.Project_Category = ddl_Category.SelectedValue.Trim(); ProjectItem.Project_AwardLevel = ddl_AwardLevel.SelectedValue.Trim(); ProjectItem.Project_PartnerType = ddl_ParterType.SelectedValue.Trim(); ProjectItem.Project_Request = ddl_Request.SelectedValue.Trim(); ProjectItem.Project_Type = ddl_Type.SelectedValue.Trim(); ProjectItem.Project_Change = ddl_Change.SelectedValue.Trim(); ProjectItem.Project_Subject = tb_Subject.Text.Trim(); ProjectItem.Project_CourseMode = ""; for (int i = 0; i < cbl_CourseMode.Items.Count; i++) { if (cbl_CourseMode.Items[i].Selected == true) { ProjectItem.Project_CourseMode += cbl_CourseMode.Items[i].Value + "|"; } } Project.Update(ProjectItem); /// ���Equipment ��Ϣ int ProjectIDs = ProjectItem.ID; ///���� /// LabMS.BLL.ProjectConsume ProjectConsume = new LabMS.BLL.ProjectConsume(); List<LabMS.Model.ProjectConsume> ls = new List<LabMS.Model.ProjectConsume>(); ls = ProjectConsume.GetModelList("ProjectID=" + ProjectIDs); try { for (int v = 0; v < ls.Count; v++) { ProjectConsume.Delete(ls[v].ID); } } catch { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('��������Ʒ��Ӵ���');window.location.href='ProjectList.aspx';</script>"); return; } LabMS.Model.ProjectConsume projectconsumemodel; int temp = 0; decimal tem = 0.0M; for (int n = 0; n < Index; n++) { projectconsumemodel = new LabMS.Model.ProjectConsume(); try { if (!string.IsNullOrEmpty(Request.Form["code" + n]) && !string.IsNullOrEmpty(Request.Form["name" + n])) { projectconsumemodel.EquipType = Request.Form["code" + n]; projectconsumemodel.EquipName = Request.Form["name" + n]; projectconsumemodel.Model = Request.Form["model" + n]; projectconsumemodel.CategoryCode = Request.Form["categorycode" + n]; projectconsumemodel.Argument = Request.Form["argument" + n]; if (int.TryParse(Request.Form["num" + n], out temp)) { projectconsumemodel.EquipNum = temp; } else { projectconsumemodel.EquipNum = 0; } projectconsumemodel.Type = "1"; projectconsumemodel.ProjectID = ProjectIDs; ProjectConsume.Add(projectconsumemodel); } } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('��������Ʒ��Ӵ���');window.location.href='ProjectList.aspx';</script>"); return; } } for (int m = 0; m < NewIndex; m++) { projectconsumemodel = new LabMS.Model.ProjectConsume(); try { if (!string.IsNullOrEmpty(Request.Form["consumpcode" + m]) && !string.IsNullOrEmpty(Request.Form["consumpname" + m])) { projectconsumemodel.EquipType = Request.Form["consumpcode" + m]; projectconsumemodel.EquipName = Request.Form["consumpname" + m]; projectconsumemodel.Model = Request.Form["consumpmodel" + m]; projectconsumemodel.CategoryCode = Request.Form["consumpcategorycode" + m]; projectconsumemodel.Argument = Request.Form["consumpargument" + m]; if (int.TryParse(Request.Form["consumpnum" + m], out temp)) { projectconsumemodel.EquipNum = temp; } else { projectconsumemodel.EquipNum = 0; } if (decimal.TryParse(Request.Form["consumpunitprice" + m], out tem)) { projectconsumemodel.UnitPrice = tem; } else { projectconsumemodel.UnitPrice = 0.0M; } if (decimal.TryParse(Request.Form["consumpmoney" + m].Trim(), out tem)) { projectconsumemodel.Money = tem.ToString(); } else { decimal unitpricetemp = 0.0M; int numtemp = 0; if (decimal.TryParse(Request.Form["consumpunitprice" + m].Trim(), out unitpricetemp) && int.TryParse(Request.Form["consumpnum" + m].Trim(), out numtemp)) { decimal moneyall = unitpricetemp * numtemp; projectconsumemodel.Money = moneyall.ToString(); } else { projectconsumemodel.Money = "0.0"; } } projectconsumemodel.ProjectID = ProjectIDs; projectconsumemodel.Type = "2"; ProjectConsume.Add(projectconsumemodel); } } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('��������Ʒ��Ӵ���,����ϵ����Ա��');window.location.href='ProjectList.aspx';</script>"); return; } } Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�ijɹ�');refreshParent();if(window.confirm('�Ƿ��б�ҳ��')){window.location.href='ProjectList.aspx';}else{window.location.href=window.location.href;}</script>"); return; }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LabMS.Model.ProjectConsume GetModel(int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,ProjectID,EquipType,EquipNum,UnitPrice,Argument,EquipName,Money,Type,CategoryCode,Model from ProjectConsume "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; LabMS.Model.ProjectConsume model=new LabMS.Model.ProjectConsume(); 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]["ProjectID"].ToString()!="") { model.ProjectID=int.Parse(ds.Tables[0].Rows[0]["ProjectID"].ToString()); } model.EquipType=ds.Tables[0].Rows[0]["EquipType"].ToString(); if(ds.Tables[0].Rows[0]["EquipNum"].ToString()!="") { model.EquipNum=int.Parse(ds.Tables[0].Rows[0]["EquipNum"].ToString()); } if(ds.Tables[0].Rows[0]["UnitPrice"].ToString()!="") { model.UnitPrice=decimal.Parse(ds.Tables[0].Rows[0]["UnitPrice"].ToString()); } model.Argument=ds.Tables[0].Rows[0]["Argument"].ToString(); model.EquipName=ds.Tables[0].Rows[0]["EquipName"].ToString(); model.Money=ds.Tables[0].Rows[0]["Money"].ToString(); model.Type=ds.Tables[0].Rows[0]["Type"].ToString(); model.CategoryCode=ds.Tables[0].Rows[0]["CategoryCode"].ToString(); model.Model=ds.Tables[0].Rows[0]["Model"].ToString(); return model; } else { return null; } }
protected void Submit_Click(object sender, EventArgs e) { if (tb_Code.Text.Trim() == "") { LabMS.Common.JShelper.JSAlert(this, "�������", "ʵ���Ų���Ϊ��"); return; } if (Project_Name.Text.Trim() == "") { LabMS.Common.JShelper.JSAlert(this, "�������", "ʵ�����Ʋ���Ϊ��"); return; } if (Project_Category.SelectedValue.Trim() == "0") { LabMS.Common.JShelper.JSAlert(this, "�������", "ʵ����Ŀ�����Ϊ��"); return; } if (Project_Lab.SelectedValue.Trim() == "0") { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀ����ʵ���Ҳ���Ϊ��"); return; } if (Project_StartTime.Text.Trim() == "") { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀ���ʱ�䲻��Ϊ��"); return; } if (Project_EndTime.Text.Trim() == "") { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀ���ʱ�䲻��Ϊ��"); return; } if (Project_StartWeek.Text.Trim() == "" || !IsNumber(Project_StartWeek.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀ����ܴ�����������������Ƿ�Ϊ�ջ�ȷ������Ϊ����"); return; } if (Project_EndWeek.Text.Trim() == "" || !IsNumber(Project_EndWeek.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀ�����ܴ�����������������Ƿ�Ϊ�ջ�ȷ������Ϊ����"); return; } if ((Convert.ToInt32(Project_EndWeek.Text.Trim())) < Convert.ToInt32(Project_StartWeek.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀ�ܴδ�С����"); return; } if (Project_ClassHourse.Text.Trim() == "" || !IsNumber(Project_ClassHourse.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������", "ʵ��ѧʱ�������,���������Ƿ�Ϊ�ջ�ȷ������Ϊ����"); return; } if (Project_ExpHouse.Text.Trim() == "" || !IsNumber(Project_ExpHouse.Text.Trim())) { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀʵ��ѧʱ�������,���������Ƿ�Ϊ�ջ�ȷ������Ϊ����"); return; } if (tb_SubjectCode.Text.Trim() == "") { LabMS.Common.JShelper.JSAlert(this, "�������", "��Ŀѧ�Ʋ���Ϊ��"); return; } if (ddl_ParterType.SelectedValue == "0") { LabMS.Common.JShelper.JSAlert(this, "", "��ѡ��ʵ�������"); return; } if (ddl_Type.SelectedValue == "0") { LabMS.Common.JShelper.JSAlert(this, "", "��ѡ��ʵ������"); return; } if (ddl_Request.SelectedValue == "0") { LabMS.Common.JShelper.JSAlert(this, "", "��ѡ��ʵ������"); return; } if (ddl_Profess.SelectedValue == "0") { LabMS.Common.JShelper.JSAlert(this, "�������", "��ѡ����Ӧ��רҵ"); return; } #region Validate int Index = Convert.ToInt32(tb_EIndex.Value); 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["model" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "�����ͺŲ���Ϊ��"); return; } if (string.IsNullOrEmpty(Request.Form["categorycode" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "�������Ų���Ϊ��"); return; } if (string.IsNullOrEmpty(Request.Form["argument" + i])) { LabMS.Common.JShelper.JSAlert(this, "error", "���������Ϊ��"); return; } } } int NewIndex = Convert.ToInt32(tb_ConsumpIndex.Value); for (int j = 0; j < NewIndex; j++) { if (!string.IsNullOrEmpty(Request.Form["consumpcode" + j]) && !string.IsNullOrEmpty(Request.Form["consumpname" + j])) { if (string.IsNullOrEmpty(Request.Form["consumpmodel" + j])) { LabMS.Common.JShelper.JSAlert(this, "error", "����Ʒ�ͺŲ���Ϊ��"); return; } if (string.IsNullOrEmpty(Request.Form["consumpcategorycode" + j])) { LabMS.Common.JShelper.JSAlert(this, "error", "����Ʒ���Ų���Ϊ��"); return; } if (string.IsNullOrEmpty(Request.Form["consumpunitprice" + j])) { LabMS.Common.JShelper.JSAlert(this, "error", "����Ʒ���۲���Ϊ��"); return; } } } #endregion Validate 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" }; LabMS.BLL.Project Project = new LabMS.BLL.Project(); LabMS.Model.Project ProjectItem = new LabMS.Model.Project(); try { DateTime StarTime = DateTime.ParseExact(Project_StartTime.Text.Trim(), DateTimeList, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite); DateTime EndTime = DateTime.ParseExact(Project_EndTime.Text.Trim(), DateTimeList, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowInnerWhite); if (DateTime.Compare(StarTime, EndTime) <= 0) { ProjectItem.Project_StartTime = StarTime; ProjectItem.Project_EndTime = EndTime; } else { LabMS.Common.JShelper.JSAlert(this, "����ʱ���С����", "����ϸ�˶ԣ������ʱ��ʹ�С"); return; } } catch { LabMS.Common.JShelper.JSAlert(this, "ʱ���������", "��ȷ��ʱ�������ʽ��ʱ����Ⱥ�˳���Ƿ���ȷ"); return; } ProjectItem.Project_Code = tb_Code.Text.Trim(); ProjectItem.Project_Name = Project_Name.Text.Trim(); ProjectItem.Project_StartWeek = new int?(Convert.ToInt32(Project_StartWeek.Text.Trim())); ProjectItem.Project_EndWeek = new int?(Convert.ToInt32(Project_EndWeek.Text.Trim())); ProjectItem.Project_ClassHourse = new int?(Convert.ToInt32(Project_ClassHourse.Text.Trim())); ProjectItem.Project_ExpHouse = Convert.ToInt32(Project_ExpHouse.Text.Trim()); ProjectItem.Project_SubmitTime = DateTime.Now; if (IsNumber(Project_Cunsume.Text.Trim()) && !string.IsNullOrEmpty(Project_Cunsume.Text.Trim())) { ProjectItem.Project_Consume = new int?(Convert.ToInt32(Project_Cunsume.Text.Trim())); } if (IsNumber(Project_PatnerNum.Text.Trim()) && !string.IsNullOrEmpty(Project_PatnerNum.Text.Trim())) { ProjectItem.Project_PartnerNum = Convert.ToInt32(Project_PatnerNum.Text.Trim()); } if (IsNumber(Project_PerConsume.Text.Trim()) && !string.IsNullOrEmpty(Project_PerConsume.Text.Trim())) { ProjectItem.Project_PerConsume = Convert.ToInt32(Project_PerConsume.Text.Trim()); } ProjectItem.Project_Lab = new int?(Convert.ToInt32(Project_Lab.SelectedValue)); ProjectItem.Project_Content = Project_Content.Text.TrimEnd(); ProjectItem.Project_Professional = Convert.ToInt32(ddl_Profess.SelectedValue); ProjectItem.Project_Category = Project_Category.SelectedValue.Trim(); ProjectItem.Project_AwardLevel = ddl_AwardLevel.SelectedValue.Trim(); ProjectItem.Project_PartnerType = ddl_ParterType.SelectedValue.Trim(); ProjectItem.Project_Request = ddl_Request.SelectedValue.Trim(); ProjectItem.Project_Type = ddl_Type.SelectedValue.Trim(); ProjectItem.Project_Change = ddl_Change.SelectedValue.Trim(); ProjectItem.Project_Subject = tb_SubjectCode.Text; ProjectItem.Project_PartnerType = ddl_ParterType.SelectedValue; int teamnum = 0; if (int.TryParse(tb_TeamNum.Text.Trim(), out teamnum)) { ProjectItem.Project_PartnerTeamNum = teamnum; } else { ProjectItem.Project_PartnerTeamNum = 0; } for (int i = 0; i < cbl_CourseMode.Items.Count; i++) { if (cbl_CourseMode.Items[i].Selected == true) { ProjectItem.Project_CourseMode += cbl_CourseMode.Items[i].Value + "|"; } } int ProjectID = Project.Add(ProjectItem); //���ʵ�����ĺͺIJ� int tem = 0; decimal temp; LabMS.BLL.ProjectConsume ProjectConsume = new LabMS.BLL.ProjectConsume(); LabMS.Model.ProjectConsume model; for (int n = 0; n < Index; n++) { if (!string.IsNullOrEmpty(Request.Form["code" + n]) && !string.IsNullOrEmpty(Request.Form["name" + n])) { model = new LabMS.Model.ProjectConsume(); model.EquipType = Request.Form["code" + n].ToString(); model.EquipName = Request.Form["name" + n].ToString(); model.Model = Request.Form["model" + n].ToString(); model.CategoryCode = Request.Form["categorycode" + n].ToString(); model.Argument = Request.Form["argument" + n].ToString(); if (int.TryParse(Request.Form["num" + n].ToString(), out tem)) { model.EquipNum = tem; } model.Type = "1"; model.ProjectID = ProjectID; try { ProjectConsume.Add(model); } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�����������," + ex.Message + "');window.location.href='ProjectList.aspx';</script>"); } } } for (int m = 0; m < NewIndex; m++) { if (!string.IsNullOrEmpty(Request.Form["consumpcode" + m]) && !string.IsNullOrEmpty(Request.Form["consumpname" + m])) { model = new LabMS.Model.ProjectConsume(); model.EquipType = Request.Form["consumpcode" + m].ToString(); model.EquipName = Request.Form["consumpname" + m].ToString(); model.CategoryCode = Request.Form["consumpcategorycode" + m].ToString(); model.Model = Request.Form["consumpmodel" + m].ToString(); if (int.TryParse(Request["consumpnum" + m].ToString(), out tem)) { model.EquipNum = tem; } else { model.EquipNum = 1; } if (decimal.TryParse(Request.Form["consumpunitprice" + m].ToString(), out temp)) { model.UnitPrice = temp; } else { model.UnitPrice = 0.0M; } decimal money = (model.UnitPrice.Value * model.EquipNum.Value); model.Money = money.ToString(); //if(!string.IsNullOrEmpty(Request.Form["consumpmoney"+m])) //{ // model.Money = Request.Form["consumpmoney" + m].ToString(); //} //else //{ // model.Money = "0"; //} model.Type = "2"; model.ProjectID = ProjectID; try { ProjectConsume.Add(model); } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('��������Ʒ����" + ex.Message + "');window.location.href='ProjectList.aspx';</script>"); } } } Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('��ӳɹ�,��������Ŀ�б�ҳ�棡');if(window.confirm('�����б�ҳ�棡')){window.location.href='ProjectList.aspx';}else{window.location.href='ProjectPre.aspx?ID=" + ProjectID + "'}; </script>"); return; }