public static BG_EstimatesAllocation AddBG_EstimatesAllocation(BG_EstimatesAllocation bG_EstimatesAllocation) { string sql = "INSERT BG_EstimatesAllocation (DepID, PIID, BEAMon, BEAYear)" + "VALUES (@DepID, @PIID, @BEAMon, @BEAYear)"; sql += " ; SELECT @@IDENTITY"; try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@DepID", bG_EstimatesAllocation.DepID), new SqlParameter("@PIID", bG_EstimatesAllocation.PIID), new SqlParameter("@BEAMon", bG_EstimatesAllocation.BEAMon), new SqlParameter("@BEAYear", bG_EstimatesAllocation.BEAYear) }; string IdStr = DBUnity.ExecuteScalar(CommandType.Text, sql, para); int newId = Convert.ToInt32(IdStr); return GetBG_EstimatesAllocationByBEAID(newId); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
protected void btnSure_DirectClick(object sender, DirectEventArgs e) { string name = ""; try { name = ComboBox1.SelectedItem.Value; } catch { X.Msg.Alert("系统提示", "请选择科目名称。").Show(); return; } if (tfMon.Text=="") { X.Msg.Alert("系统提示", "请填写经费。").Show(); return; } string bgpi = BG_BudItemsLogic.GetBG_PayIncomeByname(name); int piid = common.IntSafeConvert(bgpi.Split(',')[0]); int year = Convert.ToInt32(HidYear.Value); int depid = Convert.ToInt32(HidDepid.Value); BG_EstimatesAllocation ba = new BG_EstimatesAllocation(); ba.DepID = depid; ba.PIID = piid; ba.BEAYear = year; ba.BEAMon = ParToDecimal.ParToDel(tfMon.Text); if (Convert.ToDecimal(tatal.Value) - ba.BEAMon > 0) { if (BGBudItemsService.Isba(year, piid, depid) > 0) { ba.BEAID = BGBudItemsService.IsBEAba(year, piid, depid); BG_EstimatesAllocationManager.ModifyBG_EstimatesAllocation(ba); } else { BG_EstimatesAllocationManager.AddBG_EstimatesAllocation(ba); } Window1.Hidden = true; AddDataBind(); DtDataBind(); } else { X.Msg.Alert("提示", "预算金额不足,无法分配!").Show(); } }
public static BG_EstimatesAllocation GetBG_EstimatesAllocationByBEAID(int bEAID) { string sql = "SELECT * FROM BG_EstimatesAllocation WHERE BEAID = @BEAID"; try { SqlParameter para = new SqlParameter("@BEAID", bEAID); DataTable dt = DBUnity.AdapterToTab(sql, para); if(dt.Rows.Count > 0) { BG_EstimatesAllocation bG_EstimatesAllocation = new BG_EstimatesAllocation(); bG_EstimatesAllocation.BEAID = dt.Rows[0]["BEAID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["BEAID"]; bG_EstimatesAllocation.DepID = dt.Rows[0]["DepID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["DepID"]; bG_EstimatesAllocation.PIID = dt.Rows[0]["PIID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["PIID"]; bG_EstimatesAllocation.BEAMon = dt.Rows[0]["BEAMon"] == DBNull.Value ? 0 : (decimal)dt.Rows[0]["BEAMon"]; bG_EstimatesAllocation.BEAYear = dt.Rows[0]["BEAYear"] == DBNull.Value ? 0 : (int)dt.Rows[0]["BEAYear"]; return bG_EstimatesAllocation; } else { return null; } } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
public static bool DeleteBG_EstimatesAllocation(BG_EstimatesAllocation bG_EstimatesAllocation) { return DeleteBG_EstimatesAllocationByBEAID( bG_EstimatesAllocation.BEAID ); }
public static bool ModifyBG_EstimatesAllocation(BG_EstimatesAllocation bG_EstimatesAllocation) { string sql = "UPDATE BG_EstimatesAllocation " + "SET " + "DepID = @DepID, " + "PIID = @PIID, " + "BEAMon = @BEAMon, " + "BEAYear = @BEAYear " + "WHERE BEAID = @BEAID"; try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@BEAID", bG_EstimatesAllocation.BEAID), new SqlParameter("@DepID", bG_EstimatesAllocation.DepID), new SqlParameter("@PIID", bG_EstimatesAllocation.PIID), new SqlParameter("@BEAMon", bG_EstimatesAllocation.BEAMon), new SqlParameter("@BEAYear", bG_EstimatesAllocation.BEAYear) }; int t = DBUnity.ExecuteNonQuery(CommandType.Text, sql, para); if(t>0) { return true; } else { return false; } } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }