using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.Common; using Wellan.Data; using Wellan.Common; using System.Collections.Generic; /// /// 計算勞健保費基礎類別 /// public class LaborAndHealthFee { protected WQuery _query; protected DateTime _baseDate; protected Dictionary> _amtData; protected int _bftyp; protected string _tableName; /// 計算日期 public LaborAndHealthFee(DateTime baseDate) { WConnectionString.ConnectionConfigFile = WConfig.GetConnectionConfig(); WConnectionString.ConnectionConfigName = WConfig.GetConnectionConfigName(); _query = new WQuery(WConnectionString.GetConnectionType(), WConnectionString.GetConnectionString()); _baseDate = baseDate; } /// /// 取得特定日期的級距表 /// /// protected void GetData(DateTime aDate) { if (_amtData == null) _amtData = new Dictionary>(); if (!_amtData.ContainsKey(aDate)) { List _newAmtDataItem = new List(); // 取得適用級距表版本 DataTable _verData = _query.Select(String.Format("SELECT * FROM BFDT WHERE BFTYP={0} ORDER BY BFVER", _bftyp)); int version = 0; foreach (System.Data.DataRow row in _verData.Rows) { if (aDate.CompareTo(row["BFSDT"]) >= 0 && (row["BFEDT"] == DBNull.Value || aDate.CompareTo(row["BFEDT"]) <= 0)) { version = Convert.ToInt32(row["BFVER"]); break; } } // 取得該版本的級距表 DataTable data = _query.Select(String.Format("SELECT * FROM {1} WHERE BSVER={0} ORDER BY BSLVL", version, _tableName)); for (int i = 0; i < data.Rows.Count; i++) { _newAmtDataItem.Add(new LHFClass(Convert.ToInt32(data.Rows[i]["BSLOW"]), Convert.ToInt32(data.Rows[i]["BSHIH"]), Convert.ToInt32(data.Rows[i]["BSAMT"]))); } _amtData.Add(aDate, _newAmtDataItem); } } // 取得目前級距表 protected void GetData() { GetData(_baseDate); } /// /// 以特定日期適用的級距表,取得特定日期適用的投保薪資 /// /// /// /// protected double GetAmont(DateTime aDate, int salary) { GetData(aDate); double bsamt = 0; for (int i = 0; i < _amtData[aDate].Count; i++) { if (salary >= _amtData[aDate][i].Low && salary <= _amtData[aDate][i].High) { bsamt = _amtData[aDate][i].Amt; break; } } return bsamt; } /// /// 以目前級距表,取得投保薪資 /// /// /// protected double GetAmont(int salary) { return GetAmont(_baseDate, salary); } protected struct LHFClass { public int Low; public int High; public int Amt; public LHFClass(int aLow, int aHigh, int aAmt) { Low = aLow; High = aHigh; Amt = aAmt; } } }