private List <OfficeSupplySingle> getSupplyList(ref double allExpense) { List <OfficeSupplySingle> result = new List <OfficeSupplySingle>(); //添加单品 int row_num = Convert.ToInt16(ViewState["count"]); string[] ak = Request.Form.AllKeys; for (int i = 0; i < Request.Form.Count; i++) { //只筛选出动态生成的三个控件的值 int counter = 0; if (ak[i].IndexOf("box") > -1) { OfficeSupplySingle item = new OfficeSupplySingle(); item.Name = Request.Form[i++].ToString(); item.Version = Request.Form[i++].ToString(); item.Price = Convert.ToDouble(Request.Form[i++]); item.Counter = Convert.ToInt16(Request.Form[i++]); allExpense += item.Counter * item.Price; result.Add(item); } } return(result); }
/// <summary> /// 根据编号获取办公用品申购记录 /// </summary> /// <param name="id"></param> /// <returns></returns> public static OfficeSupplyApply GetOfficeSupplyApplyByID(int id) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand("SELECT * FROM [OfficeSupplyApplies] WHERE [ApplyID] = @ApplyID", conn); cmd.Parameters.Add("@ApplyID", SqlDbType.Int).Value = id; conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); OfficeSupplyApply oi = null; if (sdr.Read()) { oi = new OfficeSupplyApply(); oi.officeList = new List <OfficeSupplySingle>(); oi.staffName = (string)sdr["StaffName"]; oi.department = (string)sdr["Department"]; oi.reason = (string)sdr["Reason"]; oi.applyDate = Convert.ToDateTime(sdr["ApplyDate"]); oi.ApproveProcess = sdr["ApproveProcess"] == DBNull.Value ? "" : (string)sdr["ApproveProcess"]; } sdr.Close(); conn.Close(); double all = 0.0; List <OfficeSupplySingle> result = OfficeSupplySingle.GetOfficeSupplyListByID(id); oi.officeList.AddRange(result); foreach (OfficeSupplySingle o in result) { all += o.AllExpense; } oi.allExpensive = all; return(oi); }
private static void SetSingleSupply(OfficeSupplySingle os, int applyID, SqlConnection conn) { SqlCommand cmd = new SqlCommand("INSERT INTO [OfficeSupplies] ([ApplyID], [Name], [Version], [Price], [Counter]) VALUES (@ApplyID, @Name, @Version, @Price, @Counter)", conn); cmd.Parameters.Add("@ApplyID", SqlDbType.Int).Value = applyID; cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = os.Name; cmd.Parameters.Add("@Version", SqlDbType.VarChar).Value = os.Version; cmd.Parameters.Add("@Price", SqlDbType.Float).Value = os.Price; cmd.Parameters.Add("@Counter", SqlDbType.Int).Value = os.Counter; cmd.ExecuteNonQuery(); }
protected void confirm_Click(object sender, EventArgs e) { OfficeSupplyApply oi = new OfficeSupplyApply(); oi.StaffName = staffName.Text; oi.Department = department.Text; oi.ApplyDate = DateTime.Today; oi.Reason = reason.Text; oi.ApproveProcess = ""; int recordid = OfficeSupplyApply.SetOfficeSupplyApplyByID(-1, oi, ProjectInfo.getProjectInfoByCode(projectCodeList.SelectedValue).Manager); double allExpense = 0.0; List <OfficeSupplySingle> supplyList = getSupplyList(ref allExpense); OfficeSupplySingle.SetOfficeSupplySingle(supplyList, recordid); oi.AllExpensive = allExpense; OfficeSupplyApply.SetOfficeSupplyApplyByID(recordid, oi, ProjectInfo.getProjectInfoByCode(projectCodeList.SelectedValue).Manager); Response.Redirect("~/Account/ApplyListPage.aspx"); }
/// <summary> /// 根据申购编号,获取对应的办公用品清单 /// </summary> /// <param name="id"></param> /// <returns></returns> public static List <OfficeSupplySingle> GetOfficeSupplyListByID(int id) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand("SELECT * FROM [OfficeSupplies] WHERE [ApplyID] = @ApplyID", conn); cmd.Parameters.Add("@ApplyID", SqlDbType.Int).Value = id; conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); List <OfficeSupplySingle> result = new List <OfficeSupplySingle>(); while (sdr.Read()) { OfficeSupplySingle temp = new OfficeSupplySingle(); temp.name = (string)sdr["Name"]; temp.version = (string)sdr["Version"]; temp.counter = Convert.ToInt32(sdr["Counter"]); temp.price = (double)sdr["Price"]; temp.allExpense = temp.price * temp.counter; result.Add(temp); } conn.Close(); return(result); }