protected override Boolean WfDisplayMode() { vw_zinvt001 masterModel = null; try { if (DrMaster != null && DrMaster.RowState != DataRowState.Detached) { masterModel = DrMaster.ToItem <vw_zinvt001>(); WfSetDocPicture("", masterModel.igaconf, "", pbxDoc); if ((FormEditMode == YREditType.新增 || FormEditMode == YREditType.修改)) { if (BaaModel == null || GlobalFn.varIsNull(BaaModel.baa04)) { WfShowErrorMsg("未設定本國幣別,請先設定!"); } BekModel = BoBas.OfGetBekModel(BaaModel.baa04); if (BekModel == null) { WfShowErrorMsg(string.Format("未設定此幣別{0},於幣別基本資料檔,請先設定!", BaaModel.baa04)); } } } else { WfSetDocPicture("", "", "", pbxDoc); } if (FormEditMode == YREditType.NA) { WfSetControlsReadOnlyRecursion(this, true); } else { WfSetControlsReadOnlyRecursion(this, false); //先全開 WfSetControlReadonly(uGridMaster, true); //主表grid不可編輯 WfSetControlsReadOnlyRecursion(ute_iga01.Parent, true); WfSetControlsReadOnlyRecursion(ute_igaconu.Parent, true); //明細先全開,並交由 WfSetDetailDisplayMode處理 } return(true); } catch (Exception ex) { throw ex; } }
/********** 其他常用function ********/ #region OfGetPrice /// <summary> /// /// </summary> /// <param name="pSbc01">價格條件</param> /// <param name="pCust">客戶編號</param> /// <param name="pItem">料號</param> /// <param name="pUnit">單位</param> /// <param name="pDate">日期</param> /// <param name="pCurrency">幣別</param> /// <param name="pType">1.報價 2.訂單 3.出貨單</param> /// <param name="pQty">數量</param> /// <param name="pTaxYN">含稅否</param> /// <param name="pTaxRate">稅率</param> /// <param name="pExRate">匯率</param> /// <param name="pPrice">回傳價格</param> /// <returns></returns> public Result OfGetPrice(string pSbc01, string pCust, string pItem, string pUnit, DateTime?pDate, string pCurrency, string pType, decimal pQty, string pTaxYN, decimal pTaxRate, decimal pExRate, out decimal pPrice ) { Result rtnResult = null; string sqlSelect = ""; List <SqlParameter> sqlParmList = null; List <sbc_tb> sbcList = null; BasBLL boBas = null; bek_tb bekModel = null; decimal tempPrice = 0; bool flag = false; pPrice = 0; try { rtnResult = new Result(); rtnResult.Key1 = pItem; boBas = new BasBLL(OfGetConntion()); boBas.TRAN = this.TRAN; sbcList = OfgetSbcList(pSbc01); if (sbcList == null || sbcList.Count == 0) { rtnResult.Message = "未設定取價原則!"; return(rtnResult); } bekModel = boBas.OfGetBekModel(pCurrency); if (bekModel == null) { rtnResult.Message = "查無此幣別資料!"; return(rtnResult); } foreach (sbc_tb sbcModel in sbcList.OrderBy(p => p.sbc04)) { switch (sbcModel.sbc03.ToUpper()) { case "A1": //依料號主檔 考量含稅否及匯率 sqlParmList = new List <SqlParameter>(); sqlParmList.Add(new SqlParameter("@ica01", pItem)); if (pTaxYN == "Y") { sqlSelect = @"SELECT ica11 FROM ica_tb WHERE ica01=@ica01"; } else { sqlSelect = @"SELECT ica10 FROM ica_tb WHERE ica01=@ica01"; } tempPrice = GlobalFn.isNullRet(OfGetFieldValue(sqlSelect, sqlParmList.ToArray()), 0m); break; case "A2": //依料號客戶價格 雖然key值只有料號+客戶編號+幣別,但還是得加含稅否來做處理 sqlParmList = new List <SqlParameter>(); sqlParmList.Add(new SqlParameter("@sdd01", pItem)); sqlParmList.Add(new SqlParameter("@sdd02", pCust)); sqlParmList.Add(new SqlParameter("@sdd03", pCurrency)); sqlParmList.Add(new SqlParameter("@sdd08", pTaxYN)); sqlSelect = @"SELECT sdd09 FROM sdd_tb WHERE sdd01=@sdd01 AND sdd02=@sdd02 AND sdd03=@sdd03 AND sdd08=@sdd08 "; tempPrice = GlobalFn.isNullRet(OfGetFieldValue(sqlSelect, sqlParmList.ToArray()), 0m); break; case "A3": //依產品主檔 break; } if (sbcModel.sbc03.ToUpper() == "A1" && tempPrice > 0) { pPrice = tempPrice / pExRate; pPrice = GlobalFn.Round(pPrice, bekModel.bek03); break; } if (sbcModel.sbc03.ToUpper() == "A2" && tempPrice > 0) { pPrice = tempPrice; pPrice = GlobalFn.Round(pPrice, bekModel.bek03); break; } } rtnResult.Success = true; return(rtnResult); } catch (Exception ex) { throw ex; } }
/********** 其他常用function ********/ #region OfGetPrice /// <summary> /// /// </summary> /// <param name="pPbc01">價格條件</param> /// <param name="pVendor">客戶編號</param> /// <param name="pItem">料號</param> /// <param name="pUnit">單位</param> /// <param name="pDate">日期</param> /// <param name="pCurrency">幣別</param> /// <param name="pType">2.採購 3.收貨</param> /// <param name="pQty">數量</param> /// <param name="pTaxYN">含稅否</param> /// <param name="pTaxRate">稅率</param> /// <param name="pExRate">匯率</param> /// <param name="pUtaxPrice">回傳未稅價格</param> /// <param name="pTaxPrice">回傳含稅價格</param> /// <returns></returns> public Result OfGetPrice(string pPbc01, string pVendor, string pItem, string pUnit, DateTime?pDate, string pCurrency, string pType, decimal pQty, string pTaxYN, decimal pTaxRate, decimal pExRate, out decimal pUtaxPrice, out decimal pTaxPrice ) { Result rtnResult = null; string sqlSelect = ""; List <SqlParameter> sqlParmList = null; List <pbc_tb> pbcList = null; ica_tb icaModel = null; bek_tb bekModel = null; InvBLL boInv = null; BasBLL boBas = null; decimal tempUtaxPrice = 0, tempTaxPrice = 0, unitRate = 0; bool flag = false; pUtaxPrice = 0; pTaxPrice = 0; try { rtnResult = new Result(); rtnResult.Key1 = pItem; boInv = new InvBLL(OfGetConntion()); boInv.TRAN = this.TRAN; boBas = new BasBLL(OfGetConntion()); boBas.TRAN = this.TRAN; pbcList = OfgetPbcList(pPbc01); if (pbcList == null || pbcList.Count == 0) { rtnResult.Message = "未設定取價原則!"; return(rtnResult); } icaModel = boInv.OfGetIcaModel(pItem); if (icaModel == null) { rtnResult.Message = "查無此料號資料!"; return(rtnResult); } bekModel = boBas.OfGetBekModel(pCurrency); if (bekModel == null) { rtnResult.Message = "查無此幣別資料!"; return(rtnResult); } foreach (pbc_tb pbcModel in pbcList.OrderBy(p => p.pbc04)) { switch (pbcModel.pbc03.ToUpper()) { case "A1": //依料號最近市價 考量含稅否及匯率 tempUtaxPrice = icaModel.ica19; if (pTaxYN == "Y") { tempTaxPrice = tempUtaxPrice * (1 + pTaxRate / 100); } //取得單位換算率 傳入單位與採購單位的換算率--這個適用A1跟A2 flag = boInv.OfGetUnitCovert(pItem, icaModel.ica08, pUnit, out unitRate); if (flag == false) { rtnResult.Message = "取得料號換算率失敗!"; return(rtnResult); } tempUtaxPrice = tempUtaxPrice * unitRate; tempTaxPrice = tempTaxPrice * unitRate; break; case "A2": //依料號最近採購價 考量含稅否及匯率 tempUtaxPrice = icaModel.ica18; if (pTaxYN == "Y") { tempTaxPrice = tempUtaxPrice * (1 + pTaxRate / 100); } //取得單位換算率 傳入單位與採購單位的換算率--這個適用A1跟A2 flag = boInv.OfGetUnitCovert(pItem, icaModel.ica08, pUnit, out unitRate); if (flag == false) { rtnResult.Message = "取得料號換算率失敗!"; return(rtnResult); } tempUtaxPrice = tempUtaxPrice * unitRate; tempTaxPrice = tempTaxPrice * unitRate; break; case "A3": //依料號供應商單價 var pddModel = OfGetPddModel(pItem, pVendor, pCurrency); if (pddModel == null) { continue; } tempUtaxPrice = pddModel.pdd09; tempTaxPrice = pddModel.pdd10; //取得匯率 //取得單位換算率 傳入單位與採購單位的換算率--這個適用A1跟A2 flag = boInv.OfGetUnitCovert(pItem, pddModel.pdd12, pUnit, out unitRate); if (flag == false) { rtnResult.Message = "取得料號換算率失敗!"; return(rtnResult); } tempUtaxPrice = tempUtaxPrice * unitRate; tempTaxPrice = tempTaxPrice * unitRate; break; } if (pTaxYN == "Y" && tempTaxPrice == 0) { continue; } if (pTaxYN != "Y" && tempUtaxPrice == 0) { continue; } if (pbcModel.pbc03.ToUpper() == "A1" || pbcModel.pbc03.ToUpper() == "A2") { pUtaxPrice = tempUtaxPrice / pExRate; pTaxPrice = tempTaxPrice / pExRate; pUtaxPrice = GlobalFn.Round(pUtaxPrice, bekModel.bek03); pTaxPrice = GlobalFn.Round(pTaxPrice, bekModel.bek03); break; } if (pbcModel.pbc03.ToUpper() == "A3") //查詢已包含幣別,所以不用考量匯率 { pUtaxPrice = GlobalFn.Round(tempUtaxPrice, bekModel.bek03); pTaxPrice = GlobalFn.Round(tempTaxPrice, bekModel.bek03); break; } } rtnResult.Success = true; return(rtnResult); } catch (Exception ex) { throw ex; } }