protected void btnAdd_Click(object sender, EventArgs e) { ptOfficeResInStorageDetail data = this.GetData(); ptOfficeResStock stockData = this.GetStockData(); if (this.OperateType == "add") { this.amAction.AddStock(stockData); int num = this.amAction.Add(data); if (num > 0) { this.Page.RegisterStartupScript("", "<script>alert('添加成功!');returnValue=true;window.close();</script>"); } else { this.Page.RegisterStartupScript("", "<script>alert('没有相关数据可添加!');</script>"); } } if (this.OperateType == "upd") { this.amAction.UpdateStock(stockData, this.RecordID); int num = this.amAction.Update(data); if (num > 0) { this.Page.RegisterStartupScript("", "<script>alert('修改成功!');returnValue=true;window.close();</script>"); return; } this.Page.RegisterStartupScript("", "<script>alert('没有相关数据可更新!');</script>"); } }
public int AddStock(ptOfficeResStock of) { StringBuilder builder = new StringBuilder(); builder.Append(string.Concat(new object[] { " if not exists(select top 1 RecordID from OA_OfficeRes_Stock where DepotID='", of.DepotID, "' and MaterialID='", of.MaterialID, "' ) " })); builder.Append(" begin "); builder.Append("insert into OA_OfficeRes_Stock("); builder.Append("DepotID,MaterialID,Number,AvgPrice"); builder.Append(")"); builder.Append(" values ("); builder.Append(of.DepotID + ","); builder.Append(of.MaterialID + ","); builder.Append(of.Number + ","); builder.Append(of.AvgPrice); builder.Append(")"); builder.Append(" end "); builder.Append(" else "); builder.Append(" begin "); builder.Append(" declare @snum decimal(10,2) set @snum=0.00 "); builder.Append(" declare @sprice decimal(10,2) set @sprice=0.00 "); builder.Append(string.Concat(new object[] { " select @snum=isnull(Number,0),@sprice=isnull(AvgPrice,0) from OA_OfficeRes_Stock where DepotID='", of.DepotID, "' and MaterialID='", of.MaterialID, "' " })); builder.Append(" update OA_OfficeRes_Stock set "); builder.Append(string.Concat(new object[] { " AvgPrice=(@snum*@sprice+", of.Number * of.AvgPrice, ")/(select case @snum+", of.Number, " when 0 then 1 else @snum+", of.Number, " end)," })); builder.Append(" Number=(@snum+" + of.Number + ")"); builder.Append(" where "); builder.Append(" DepotID=" + of.DepotID); builder.Append(" and MaterialID=" + of.MaterialID); builder.Append(" end "); return(publicDbOpClass.ExecSqlString(builder.ToString())); }
protected void btnAdd_Click(object sender, EventArgs e) { ptOfficeResStock data = this.GetData(); if (this.OperateType == "add") { if (this.hrAction.Exists(this.DepotID, int.Parse(this.HdnMatterialID.Value))) { this.Page.RegisterStartupScript("", "<script>alert('相关数据已存在!');</script>"); } else { int num = this.hrAction.Add(data); if (num > 0) { this.Page.RegisterStartupScript("", "<script>alert('添加成功!');returnValue=true;window.close();</script>"); } else { this.Page.RegisterStartupScript("", "<script>alert('没有相关数据可添加!');</script>"); } } } if (this.OperateType == "upd") { int num = this.hrAction.Update(data); if (num > 0) { this.Page.RegisterStartupScript("", "<script>alert('修改成功!');returnValue=true;window.close();</script>"); return; } this.Page.RegisterStartupScript("", "<script>alert('没有相关数据可更新!');</script>"); } }
public int Update(ptOfficeResStock model) { StringBuilder builder = new StringBuilder(); builder.Append("update OA_OfficeRes_Stock set "); builder.Append("Number=" + model.Number + ","); builder.Append("AvgPrice=" + model.AvgPrice); builder.Append(" where DepotID=" + model.DepotID); builder.Append(" and MaterialID=" + model.MaterialID); return(publicDbOpClass.ExecSqlString(builder.ToString())); }
public int Add(ptOfficeResStock model) { StringBuilder builder = new StringBuilder(); builder.Append("insert into OA_OfficeRes_Stock("); builder.Append("DepotID,MaterialID,Number,AvgPrice"); builder.Append(")"); builder.Append(" values ("); builder.Append(model.DepotID + ","); builder.Append(model.MaterialID + ","); builder.Append(model.Number + ","); builder.Append(model.AvgPrice); builder.Append(")"); return(publicDbOpClass.ExecSqlString(builder.ToString())); }
public ptOfficeResStock GetModel(int MaterialID) { StringBuilder builder = new StringBuilder(); builder.Append("select * "); builder.Append(" RecordID,DepotID,MaterialID,Number,AvgPrice "); builder.Append(" from OA_OfficeRes_Stock "); builder.Append(" where MaterialID=" + MaterialID); ptOfficeResStock stock = new ptOfficeResStock(); DataSet set = publicDbOpClass.DataSetQuary(builder.ToString()); if (set.Tables[0].Rows.Count <= 0) { return(null); } if (set.Tables[0].Rows[0]["RecordID"].ToString() != "") { stock.RecordID = int.Parse(set.Tables[0].Rows[0]["RecordID"].ToString()); } if (set.Tables[0].Rows[0]["DepotID"].ToString() != "") { stock.DepotID = int.Parse(set.Tables[0].Rows[0]["DepotID"].ToString()); } if (set.Tables[0].Rows[0]["MaterialID"].ToString() != "") { stock.MaterialID = int.Parse(set.Tables[0].Rows[0]["MaterialID"].ToString()); } if (set.Tables[0].Rows[0]["Number"].ToString() != "") { stock.Number = decimal.Parse(set.Tables[0].Rows[0]["Number"].ToString()); } if (set.Tables[0].Rows[0]["AvgPrice"].ToString() != "") { stock.AvgPrice = decimal.Parse(set.Tables[0].Rows[0]["AvgPrice"].ToString()); } return(stock); }
public int UpdateStock(ptOfficeResStock of, int RecordID) { StringBuilder builder = new StringBuilder(); builder.Append(string.Concat(new object[] { " if not exists(select top 1 RecordID from OA_OfficeRes_Stock where DepotID='", of.DepotID, "' and MaterialID='", of.MaterialID, "' ) " })); builder.Append(" begin "); builder.Append("insert into OA_OfficeRes_Stock("); builder.Append("DepotID,MaterialID,Number,AvgPrice"); builder.Append(")"); builder.Append(" values ("); builder.Append(of.DepotID + ","); builder.Append(of.MaterialID + ","); builder.Append(of.Number + ","); builder.Append(of.AvgPrice); builder.Append(")"); builder.Append(" end "); builder.Append(" else "); builder.Append(" begin "); builder.Append(" declare @num decimal(10,2) set @num=0.00 "); builder.Append(" declare @price decimal(10,2) set @price=0.00 "); builder.Append(" declare @Storagenum decimal(10,2) set @Storagenum=0.00 "); builder.Append(" declare @Storageprice decimal(10,2) set @Storageprice=0.00 "); builder.Append(string.Concat(new object[] { " select @num=isnull(Number,0),@price=isnull(AvgPrice,0) from OA_OfficeRes_Stock where DepotID='", of.DepotID, "' and MaterialID='", of.MaterialID, "' " })); builder.Append(string.Concat(new object[] { " select @Storagenum=isnull(Amount,0),@Storageprice=isnull(InStoragePrice,0) from oa_OfficeRes_InStorage_Detail where RecordID='", RecordID, "' and MaterialID='", of.MaterialID, "' " })); builder.Append(" declare @tempnum decimal(10,2) set @tempnum=0.00 "); builder.Append(" select @tempnum=(case @num-@Storagenum when 0 then 1 else @num-@Storagenum end) "); builder.Append(" select @price=(@num*@price-@Storagenum*@Storageprice)/@tempnum "); builder.Append(" select @num=@num-@Storagenum "); builder.Append(" update OA_OfficeRes_Stock set "); builder.Append(string.Concat(new object[] { " AvgPrice=(@num*@price+", of.Number * of.AvgPrice, ")/(select case @num+", of.Number, " when 0 then 1 else @num+", of.Number, " end)," })); builder.Append(" Number=(@num+" + of.Number + ")"); builder.Append(" where "); builder.Append(" DepotID=" + of.DepotID); builder.Append(" and MaterialID=" + of.MaterialID); builder.Append(" end "); return(publicDbOpClass.ExecSqlString(builder.ToString())); }