private void btnSave_Click(object sender, EventArgs e) { try { List <Bus_PurchasingMG_UnitPriceList> lstTemp = new List <Bus_PurchasingMG_UnitPriceList>(); Bus_PurchasingMG_UnitPriceList tempInfo = new Bus_PurchasingMG_UnitPriceList(); tempInfo.GoodsID = Convert.ToInt32(txtGoodsCode.Tag); tempInfo.Provider = txtProvider.Text; tempInfo.Rate = Convert.ToInt32(numRate.Value); tempInfo.UnitPrice = numUnitPrice.Value; tempInfo.ValidityStart = dtpStart.Value.Date; tempInfo.ValidityEnd = dtpEnd.Value.Date; lstTemp.Add(tempInfo); _Service_UnitList.SaveInfo(lstTemp); MessageDialog.ShowPromptMessage("保存成功"); DataGridViewShow(); } catch (Exception ex) { MessageDialog.ShowPromptMessage(ex.Message); } }
private void btnInput_Click(object sender, EventArgs e) { try { DataTable dtTemp = ExcelHelperP.RenderFromExcel(openFileDialog1); if (dtTemp == null) { return; } if (!dtTemp.Columns.Contains("图号型号")) { throw new Exception("文件无【图号型号】列名"); } if (!dtTemp.Columns.Contains("物品名称")) { throw new Exception("文件无【物品名称】列名"); } if (!dtTemp.Columns.Contains("规格")) { throw new Exception("文件无【规格】列名"); } if (!dtTemp.Columns.Contains("供应商")) { throw new Exception("文件无【供应商】列名"); } if (!dtTemp.Columns.Contains("单价")) { throw new Exception("文件无【单价】列名"); } if (!dtTemp.Columns.Contains("税率")) { throw new Exception("文件无【税率】列名"); } if (!dtTemp.Columns.Contains("有效期开始时间")) { throw new Exception("文件无【有效期开始时间】列名"); } if (!dtTemp.Columns.Contains("有效期结束时间")) { throw new Exception("文件无【有效期结束时间】列名"); } List <Bus_PurchasingMG_UnitPriceList> lstTemp = new List <Bus_PurchasingMG_UnitPriceList>(); foreach (DataRow dr in dtTemp.Rows) { if ((dr["图号型号"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dr["图号型号"].ToString())) && (dr["物品名称"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dr["物品名称"].ToString())) && (dr["规格"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dr["规格"].ToString()))) { continue; } Bus_PurchasingMG_UnitPriceList tempInfo = new Bus_PurchasingMG_UnitPriceList(); string goodsMessage = "【图号型号】:" + (dr["图号型号"] == null ? "" : dr["图号型号"].ToString().Trim()).ToString() + "【物品名称】:" + (dr["物品名称"] == null ? "" : dr["物品名称"].ToString().Trim()).ToString() + "【规格】:" + (dr["规格"] == null ? "" : dr["规格"].ToString().Trim()).ToString(); View_F_GoodsPlanCost goodsInfo = UniversalFunction.GetGoodsInfo(dr["图号型号"] == null ? "" : dr["图号型号"].ToString().Trim(), dr["物品名称"] == null ? "" : dr["物品名称"].ToString().Trim(), dr["规格"] == null ? "" : dr["规格"].ToString().Trim()); if (goodsInfo == null) { throw new Exception("未找到对应的系统物品:" + goodsMessage); } //if (goodsInfo.禁用) //{ // throw new Exception("此物品已被禁用无法导入:" + goodsMessage); //} tempInfo.GoodsID = goodsInfo.序号; string strProvicer = dr["供应商"] == null ? "" : dr["供应商"].ToString(); View_Provider provider = UniversalFunction.GetProviderInfo(strProvicer); if (provider == null) { throw new Exception("未找到对应的系统供应商:" + strProvicer); } if (!provider.是否在用) { throw new Exception("【系统供应商】:" + strProvicer + " 被禁用,无法导入"); } tempInfo.Provider = provider.供应商编码; tempInfo.Rate = dr["税率"] == null || dr["税率"].ToString().Trim() == "" ? 0 : Convert.ToInt32(dr["税率"]); tempInfo.UnitPrice = dr["单价"] == null || dr["单价"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(dr["单价"]); if (dr["有效期开始时间"] == null || dr["有效期开始时间"].ToString().Trim() == "") { throw new Exception("有效期开始时间有误:" + goodsMessage); } else { tempInfo.ValidityStart = Convert.ToDateTime(dr["有效期开始时间"]).Date; } if (dr["有效期结束时间"] == null || dr["有效期结束时间"].ToString().Trim() == "") { throw new Exception("有效期结束时间有误:" + goodsMessage); } else { tempInfo.ValidityEnd = Convert.ToDateTime(dr["有效期结束时间"]).Date; } lstTemp.Add(tempInfo); } _Service_UnitList.SaveInfo(lstTemp); MessageDialog.ShowPromptMessage("导入并保存成功"); DataGridViewShow(); } catch (Exception ex) { MessageDialog.ShowPromptMessage(ex.Message); } }
/// <summary> /// 获取合同物品表中某一产品单价 /// </summary> /// <param name="bargainNumber">合同物品号</param> /// <param name="goodsID">物品ID</param> /// <param name="provider">供应商</param> /// <returns>返回获取到的单价</returns> public decimal GetGoodsUnitPrice(string bargainNumber, int goodsID, string provider) { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; DateTime dateTemp = ServerTime.Time; var varData = from a in dataContxt.Bus_PurchasingMG_UnitPriceList where a.Provider == provider && a.GoodsID == goodsID && a.ValidityStart <= dateTemp && a.ValidityEnd >= dateTemp select a; if (varData.Count() > 0) { Bus_PurchasingMG_UnitPriceList tempList = varData .OrderByDescending(k => k.ValidityStart) .ThenByDescending(k => k.VersionNo).First(); decimal unitPrice = (decimal)tempList.UnitPrice; int rate = (int)tempList.Rate; return(unitPrice / (1m + rate / 100.0m)); } var goodsGroup = from r in dataContxt.B_BargainGoods where r.BargainNumber == bargainNumber && r.GoodsID == goodsID select r; if (goodsGroup.Count() == 0) { var varData1 = from a in dataContxt.B_OrderFormInfo where a.BargainNumber == bargainNumber || a.OrderFormNumber == bargainNumber select a; if (varData1.Count() > 0) { bargainNumber = varData1.First().BargainNumber; if (bargainNumber == "价格清单") { throw new Exception("无法获取物品单价"); } goodsGroup = from r in dataContxt.B_BargainGoods where r.BargainNumber == bargainNumber && r.GoodsID == goodsID select r; } else { throw new Exception("无法获取物品单价"); } } B_BargainInfo bargain = (from r in dataContxt.B_BargainInfo where r.BargainNumber == bargainNumber select r).Single(); if (bargain.IsOverseas) { return((decimal)goodsGroup.Single().UnitPrice); } else { return(goodsGroup.Single().UnitPrice / (1m + bargain.Cess / 100.0m)); } }
public void SaveInfo(List <Bus_PurchasingMG_UnitPriceList> lstUnitPrice) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; ctx.Connection.Open(); ctx.Transaction = ctx.Connection.BeginTransaction(); try { Bus_PurchasingMG_UnitPriceList saveInfo = new Bus_PurchasingMG_UnitPriceList(); foreach (Bus_PurchasingMG_UnitPriceList item in lstUnitPrice) { decimal versionNo = (decimal)1.00; var varData = from a in ctx.Bus_PurchasingMG_UnitPriceList where a.GoodsID == item.GoodsID && a.Provider == item.Provider select a; if (varData.Count() > 0) { var varData1 = from a in varData where a.ValidityEnd == item.ValidityEnd && a.ValidityStart == item.ValidityStart && a.UnitPrice == item.UnitPrice && a.Rate == item.Rate select a; if (varData1.Count() > 0) { continue; } Bus_PurchasingMG_UnitPriceList tempInfo = varData.OrderByDescending(k => k.VersionNo).First(); versionNo = (decimal)tempInfo.VersionNo + (decimal)0.01; } saveInfo = new Bus_PurchasingMG_UnitPriceList(); saveInfo.F_Id = Guid.NewGuid().ToString(); saveInfo.GoodsID = item.GoodsID; saveInfo.Provider = item.Provider; saveInfo.Rate = item.Rate; saveInfo.RecordTime = ServerTime.Time; saveInfo.RecordUser = BasicInfo.LoginID; saveInfo.UnitPrice = item.UnitPrice; saveInfo.VersionNo = versionNo; saveInfo.ValidityStart = item.ValidityStart; saveInfo.ValidityEnd = item.ValidityEnd; ctx.Bus_PurchasingMG_UnitPriceList.InsertOnSubmit(saveInfo); } ctx.SubmitChanges(); ctx.Transaction.Commit(); } catch (Exception ex) { ctx.Transaction.Rollback(); throw ex; } }