public int AddOilPrice(OilPrice price, BusiLog busiLog) { //SqlConnection conn = ConnectionPool.BorrowConnection(); int iRet = 0; using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { BusiLogAccess.AddBusiLog(trans, busiLog); iRet = (int)OilPriceAccess.AddOilPrice(trans, price); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); throw sex; } catch (Exception ex) { trans.Rollback(); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } return(iRet); }
private void ddlDept_SelectedIndexChanged(object sender, System.EventArgs e) { //显示最新油价 string strSql = "select top 1 * from tbOilPrice where cnvcDeptName = '" + ddlDept.SelectedItem.Text + "' and cnvcGoodsName='" + ddlGoodsName.SelectedItem.Text + "' and cnvcGoodsType='" + ddlGoodsType.SelectedItem.Text + "' order by cndPriceDate desc,cnnSerialNo desc"; DataTable dtOilPrice = ReportQueryFacade.CommonQuery(strSql); if (dtOilPrice.Rows.Count > 0) { OilPrice price = new OilPrice(dtOilPrice); txtOilPrice1.Text = price.cnnOilPrice.ToString(); txtGoodsName1.Text = price.cnvcGoodsName; txtGoodsType1.Text = price.cnvcGoodsType; txtUnit1.Text = price.cnvcUnit; txtPriceDate1.Text = price.cndPriceDate.ToString("yyyy-MM-dd"); } }
private void btnAdd_Click(object sender, System.EventArgs e) { try { decimal.Parse(txtOilPrice.Text); } catch (System.Exception) { this.Popup("请输入正确油价!"); } if (txtOilPrice.Text == "") { this.Popup("请填写参数"); return; } OilPrice price = new OilPrice(); price.cnnSerialNo = Guid.NewGuid(); price.cndPriceDate = DateTime.Now; price.cnnOilPrice = decimal.Parse(txtOilPrice.Text); price.cnvcDeptName = ddlDept.SelectedItem.Text; price.cnvcGoodsName = ddlGoodsName.SelectedItem.Text; price.cnvcGoodsType = ddlGoodsType.SelectedItem.Text; price.cnvcUnit = ddlUnit.SelectedItem.Text; price.cndPriceDate = DateTime.Parse(txtPriceDate.Text + " " + DateTime.Now.ToLongTimeString()); Dept curDept = Session[ConstValue.LOGIN_DEPT_SESSION] as Dept; Oper curOper = Session[ConstValue.LOGIN_USER_SESSION] as Oper; BusiLog busiLog = new BusiLog(); busiLog.cndOperDate = DateTime.Now; busiLog.cnnSerial = Guid.NewGuid(); busiLog.cnvcOperName = curOper.cnvcOperName; busiLog.cnvcComments = "添加油价:" + price.cnvcDeptName + "|" + price.cnnOilPrice.ToString(); busiLog.cnvcDeptID = curDept.cnvcDeptID; busiLog.cnvcDeptName = curDept.cnvcDeptName; busiLog.cnvcOperType = "BS004"; busiLog.cnvcSource = "网站"; DeptFacade.AddOilPrice(price, busiLog); Popup("油价添加成功"); ddlDept_SelectedIndexChanged(null, null); }
private void Check_Load(object sender, EventArgs e) { Voiltype.Text = OilType; Voilweight.Text = OilWeight.ToString(); Voilprice.Text = OilPrice.ToString(); Vhotdogprice.Text = HotdogPrice.ToString(); Vhotdogcount.Text = HotdogCount.ToString(); Vhamburgerprice.Text = HamburgerPrice.ToString(); Vhamburgercount.Text = HamburgerCount.ToString(); Vfrenchprice.Text = FrenchFriesPrice.ToString(); Vfrenchcount.Text = FrenchFriesCount.ToString(); Vcocacolaprice.Text = CocaColaPrice.ToString(); Vcocacolacount.Text = CocaColaCount.ToString(); Vtotal.Text = Total.ToString(); }
public static int AddOilPrice(OilPrice price, BusiLog busiLog) { int ret = 0; try { BusinessRules.SysManage.Authorization auth = new BusinessRules.SysManage.Authorization(); ret = auth.AddOilPrice(price, busiLog); } catch (SqlException sex) { LogAdapter.WriteDatabaseException(sex); throw new Exception("数据库访问异常。"); } catch (Exception ex) { LogAdapter.WriteFeaturesException(ex); throw new Exception("业务规则层异常。"); } return(ret); }
// 这里写你的代码 public static long AddOilPrice(SqlTransaction trans, OilPrice price) { return(EntityMapping.Create(price, trans)); }
//重算 public static void AgainComp(string strBeginDate, string strEndDate, BusiLog bl) { //ConnectionPool.IsCenter = false; using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); string strsql = "select * from tbConsItem where CONVERT(varchar(10),cndconsdate,121) between '" + strBeginDate + "' and '" + strEndDate + "'"; DataTable dtConsItem = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strsql); if (dtConsItem.Rows.Count == 0) { throw new BusinessException("业务异常", "没有需要更新的消费记录!"); } strsql = "select * from tbOilPrice where convert(varchar(10),cndpricedate,121) <= '" + strEndDate + "' order by cndPriceDate desc"; DataTable dtPrice = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strsql); if (dtPrice.Rows.Count == 0) { throw new BusinessException("业务异常", "没有需要更新的油价!"); } foreach (DataRow dr in dtConsItem.Rows) { ConsItem ci = new ConsItem(dr); DataRow[] drPrices = dtPrice.Select("cnvcGoodsName='" + ci.cnvcGoodsName + "' and cnvcGoodsType='" + ci.cnvcGoodsType + "' and cnvcUnit='KG' and cnvcDeptName='" + ci.cnvcDeptName + "' and cndpricedate<= '" + ci.cndConsDate.AddDays(1).ToString("yyyy-MM-dd") + "'", "cndPriceDate desc"); if (drPrices.Length == 0) { continue; } OilPrice op = new OilPrice(drPrices[0]); decimal dFee = ci.cnnKGCount * op.cnnOilPrice; if (ci.cnnPrice != op.cnnOilPrice && ci.cnnFee != dFee) { ConsItemHis cih = new ConsItemHis(ci.ToTable()); cih.cnnSerial = Guid.NewGuid(); cih.cndOperDate = dtSysTime; cih.cnvcOperName = bl.cnvcOperName; cih.cnvcComments = "|cnnSerial=" + ci.cnnSerial.ToString(); ci.cnnPrice = op.cnnOilPrice; ci.cnnFee = dFee; ci.cnvcComments = "老油价:" + cih.cnnPrice.ToString() + ",新油价:" + ci.cnnPrice.ToString(); decimal dAddFee = cih.cnnFee - dFee; BusiLog busiLog = new BusiLog(); busiLog.cndOperDate = dtSysTime; busiLog.cnnSerial = Guid.NewGuid(); busiLog.cnvcOperName = bl.cnvcOperName; busiLog.cnvcComments = "油价补差充值:" + ci.cnvcCardID + "|" + dAddFee.ToString(); busiLog.cnvcDeptID = bl.cnvcDeptID; busiLog.cnvcDeptName = bl.cnvcDeptName; busiLog.cnvcOperType = "BS012"; busiLog.cnvcSource = "网站"; // FillFee fee = new FillFee(); // fee.cndOperDate = dtSysTime; // fee.cnnFillFee = dAddFee; // fee.cnnSerial = busiLog.cnnSerial; // fee.cnvcAcctID = ci.cnvcAcctID; // fee.cnvcCompanyID = ci.cnvcCompanyID; // fee.cnvcCompanyName = ci.cnvcCompanyName; // fee.cnvcDeptID = ci.cnvcDeptID; // fee.cnvcDeptName = ci.cnvcDeptName; // fee.cnvcOperName = bl.cnvcOperName; SqlHelper.ExecuteNonQuery(trans, CommandType.Text, "update tbMebCompanyPrepay set cnnPrepayFee = cnnPrepayFee+" + dAddFee.ToString() + " where cnvcCompanyID='" + ci.cnvcCompanyID + "'"); //EntityMapping.Create(fee,trans); EntityMapping.Create(busiLog, trans); EntityMapping.Create(cih, trans); EntityMapping.Update(ci, trans); } } //日志 bl.cnnSerial = Guid.NewGuid(); bl.cndOperDate = dtSysTime; EntityMapping.Create(bl, trans); trans.Commit(); } catch (BusinessException bex) { trans.Rollback(); LogAdapter.WriteBusinessException(bex); throw bex; } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }