using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.Areas.Import.Models.approval; using DSWeb.Areas.Import.Models.XXH; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; namespace DSWeb.Areas.Import.DAL.approval { public partial class approvalDAL { #region Inquery DataList static public List GetDataList ( string strCondition, string sort ) { var strSql = new StringBuilder(); strSql.Append(" SELECT a.*,cp.name companyname, "); strSql.Append(" c.country,u.used,u.selected, u.remain,u.canbeused, "); strSql.Append(" ci.code,ci.name,ciq.ciqcode,ciq.ciqname, "); strSql.Append(" (select EnumValueName from tSysEnumValue "); strSql.Append(" where LangId=0 and EnumTypeID=10 and EnumValueID=a.SLJG) as portRef, "); strSql.Append(" (select EnumValueName from tSysEnumValue "); strSql.Append(" where LangId=0 and EnumTypeID=0 and EnumValueID=a.isdeleted) as isdeletedRef "); strSql.Append(" ,SPECIFICATIONS "); strSql.Append(" FROM [Import_approval] a "); strSql.Append(" left join import_cargoinfo ci on ci.id=a.cargoinfo_id "); strSql.Append(" left join code_country c on a.[Countryid]=c.[Countryid] "); strSql.Append(" left join vMsAppUsed U on U.[app_id]=a.[id] "); strSql.Append(" left join import_cargociq ciq on ciq.id=a.cargociq_id "); strSql.Append(" left join company cp on cp.gid=a.company "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by a.APPNO "); } return SetData(strSql); } static public approvalmb GetData(string condition) { var list = GetDataList(condition,""); if (list.Count > 0) return list[0]; return new approvalmb(); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { approvalmb data = new approvalmb(); #region Set DB data to Object data.id = Convert.ToString(reader["id"]); data.gid = Convert.ToString(reader["gid"]); data.APPNO = Convert.ToString(reader["APPNO"]); data.SQDH = Convert.ToString(reader["SQDH"]); data.SLJG = Convert.ToString(reader["SLJG"]); data.portRef = Convert.ToString(reader["portRef"]); data.Countryid = Convert.ToString(reader["Countryid"]); data.Country = Convert.ToString(reader["Country"]); data.Weight = Convert.ToString(reader["Weight"]); data.used = Convert.ToString(reader["used"]); data.selected = Convert.ToString(reader["selected"]); data.remain = Convert.ToString(reader["remain"]); data.canbeused = Convert.ToString(reader["canbeused"]); data.ValidDate = Convert.ToString(reader["ValidDate"]); data.cargoinfo_id = Convert.ToString(reader["cargoinfo_id"]); data.cargociq_id = Convert.ToString(reader["cargociq_id"]); data.AppName = Convert.ToString(reader["AppName"]); data.code = Convert.ToString(reader["code"]); data.name = Convert.ToString(reader["name"]); data.ciqcode = Convert.ToString(reader["ciqcode"]); data.ciqname = Convert.ToString(reader["ciqname"]); data.isdeletedRef = Convert.ToString(reader["isdeletedRef"]); data.isdeleted = Convert.ToString(reader["isdeleted"]); data.company = Convert.ToString(reader["company"]); data.companyname = Convert.ToString(reader["companyname"]); data.depot = Convert.ToString(reader["depot"]); data.usedweight = Convert.ToString(reader["usedweight"]); data.JustWriteoffs = Convert.ToString(reader["JustWriteoffs"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.SPECIFICATIONS = Convert.ToString(reader["SPECIFICATIONS"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 获取一个许可证目前的被使用情况 static public List GetUsing(string strCondition) { var strSql = new StringBuilder(); strSql.Append(" select st.[weight],case [cancellation_date] when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar, [cancellation_date],23) end as cancellation_date, "); strSql.Append(" (select EnumValueName from tSysEnumValue "); strSql.Append(" where LangId=0 and EnumTypeID=13 and EnumValueID=st.cancellation) as cancellationRef, "); strSql.Append(" c.contractno,m.hth,m.seller,m.buyer,convert(varchar,dbo.trimdate(m.ArrivalDate),23) ArrivalDate, "); strSql.Append(" ci.code,ci.name,ciq.ciqcode,ciq.ciqname,c.name cargoname, "); strSql.Append(" (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=3 and EnumValueID=M.MainState) as MainStateRef "); strSql.Append(" ,st.REMARK "); strSql.Append(" from import_appstate st "); strSql.Append(" left join import_cargo c on c.id=st.cargo_id "); strSql.Append(" left join Import_main m on m.contractno=c.contractno "); strSql.Append(" left join import_cargoinfo ci on ci.id = c.cargoinfo_id "); strSql.Append(" left join import_cargociq ciq on ciq.id = c.cargociq_id "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetUsing(strSql); } private static List SetUsing(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { Usingmb data = new Usingmb(); #region Set DB data to Object data.weight = Convert.ToString(reader["weight"]); data.ContractNo = Convert.ToString(reader["ContractNo"]); data.HTH = Convert.ToString(reader["HTH"]); data.seller = Convert.ToString(reader["seller"]); data.buyer = Convert.ToString(reader["buyer"]); data.code = Convert.ToString(reader["code"]); data.name = Convert.ToString(reader["name"]); data.ciqcode = Convert.ToString(reader["ciqcode"]); data.ciqname = Convert.ToString(reader["ciqname"]); data.cargoname = Convert.ToString(reader["cargoname"]); data.cancellationRef = Convert.ToString(reader["cancellationRef"]); data.cancellation_date = Convert.ToString(reader["cancellation_date"]); data.ArrivalDate = Convert.ToString(reader["ArrivalDate"]); data.MainstateRef = Convert.ToString(reader["MainstateRef"]); data.REMARK = Convert.ToString(reader["REMARK"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 以 进口国、目的港、许可证商品名称 为条件 获取历史许可证 //用于在许可证管理界面 #endregion #region 获取一个商品的配证情况 即在appstate表中这个cargo_id有多少许可证使用重量 static public List Getused(string cargo_id) { var strSql = new StringBuilder(); strSql.Append(" select isnull(sum(weight),0) count from import_appstate where cargo_id=" + cargo_id + " "); return SetGetused(strSql); } private static List SetGetused(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { HTmb data = new HTmb(); #region Set DB data to Object data.Count = Convert.ToString(reader["Count"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 参照部分 #endregion #region 设定使用某许可证的业务的用证公司,与许可证的公司相一致 static public int SetCompany ( string Approval_GID,string Companyid ) { var strSql = new StringBuilder(); strSql.Append(" update import_main set company=('" + Companyid + "') where ContractNo in( "); strSql.Append(" select ContractNo from Import_appstate where app_id=(select id from Import_approval where gid='" + Approval_GID + "')) "); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count; } #endregion } }