public static BG_Pre AddBG_Pre(BG_Pre bG_Pre)
        {
            string sql =
                "INSERT BG_Pre (PreMon, Year)" +
                "VALUES (@PreMon, @Year)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@PreMon", bG_Pre.PreMon),
                    new SqlParameter("@Year", bG_Pre.Year)
                };

                string IdStr = DBUnity.ExecuteScalar(CommandType.Text, sql, para);
                int newId = Convert.ToInt32(IdStr);
                return GetBG_PreByPreID(newId);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
        public static BG_Pre GetBG_PreByPreID(int preID)
        {
            string sql = "SELECT * FROM BG_Pre WHERE PreID = @PreID";

            try
            {
                SqlParameter para = new SqlParameter("@PreID", preID);
                DataTable dt = DBUnity.AdapterToTab(sql, para);

                if(dt.Rows.Count > 0)
                {
                    BG_Pre bG_Pre = new BG_Pre();

                    bG_Pre.PreID = dt.Rows[0]["PreID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["PreID"];
                    bG_Pre.PreMon = dt.Rows[0]["PreMon"] == DBNull.Value ? 0 : (decimal)dt.Rows[0]["PreMon"];
                    bG_Pre.Year = dt.Rows[0]["Year"] == DBNull.Value ? 0 : (int)dt.Rows[0]["Year"];

                    return bG_Pre;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 public static bool DeleteBG_Pre(BG_Pre bG_Pre)
 {
     return DeleteBG_PreByPreID( bG_Pre.PreID );
 }
        public static bool ModifyBG_Pre(BG_Pre bG_Pre)
        {
            string sql =
                "UPDATE BG_Pre " +
                "SET " +
                    "PreMon = @PreMon, " +
                    "Year = @Year " +
                "WHERE PreID = @PreID";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@PreID", bG_Pre.PreID),
                    new SqlParameter("@PreMon", bG_Pre.PreMon),
                    new SqlParameter("@Year", bG_Pre.Year)
                };

                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;
            }
        }
 protected void btnPreadd_DirectClick(object sender, DirectEventArgs e)
 {
     int curtime = common.IntSafeConvert(txtPreYear.Text.Trim());
     if (!BG_PreLogic.IsPreByYear(curtime))
     {
         BG_Pre bg_pre = new BG_Pre();
         bg_pre.PreMon = ParToDecimal.ParToDel(txtPreMon.Text.Trim());
         bg_pre.Year = Convert.ToInt32(txtPreYear.Text.Trim());
         BG_PreManager.AddBG_Pre(bg_pre);
         X.Msg.Alert("提示", "添加成功!").Show();
     }
     else
     {
         BG_Pre bg_pre = new BG_Pre();
         DataTable bgsuid = BG_PreLogic.GetBG_PreByyear(curtime);
         bg_pre.PreID = common.IntSafeConvert(bgsuid.Rows[0]["PreID"].ToString());
         bg_pre.PreMon = ParToDecimal.ParToDel(txtPreMon.Text.Trim());
         bg_pre.Year = Convert.ToInt32(txtPreYear.Text.Trim());
         bool flag = BG_PreManager.ModifyBG_Pre(bg_pre);
         if (flag)
         {
             X.Msg.Alert("提示", "修改成功!").Show();
         }
         else
         {
             X.Msg.Alert("提示", "修改失败,请与管理员联系!").Show();
         }
     }
 }
 public static bool ModifyBG_Pre(BG_Pre bG_Pre)
 {
     return BG_PreService.ModifyBG_Pre(bG_Pre);
 }
 public static bool DeleteBG_Pre(BG_Pre bG_Pre)
 {
     return BG_PreService.DeleteBG_Pre(bG_Pre);
 }
 public static BG_Pre AddBG_Pre(BG_Pre bG_Pre)
 {
     return BG_PreService.AddBG_Pre(bG_Pre);
 }