using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsCwCurrencyRate; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using System.Data.SqlClient; using DSWeb.DataAccess; using HcUtility.Core; using DSWeb.Areas.CommMng.DAL; namespace DSWeb.MvcShipping.DAL.MsCwCurrencyRateDAL { public class MsCwCurrencyRateDAL { #region 查询 static public List GetDataList(string currency, string userid, string usercode, string companyid, string sort = null) { isSaveRow(currency, userid, companyid); string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid); string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(userid); var strSql = new StringBuilder(); strSql.Append("SELECT * from cw_currency_rate where ACCDATE like '" + strCwACCDATE.Trim().Substring(0, 4) + "%' and STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");// and CORPID='" + companyid + "' if (!string.IsNullOrEmpty(currency)) { strSql.Append(" and LINKGID in (select gid from code_currency where CODENAME='" + currency + "')"); } // var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by LINKGID,ACCDATE"); } return SetData(strSql); } static public MsCwCurrencyRate GetData(string currency, string companyid, string userid) { string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid); string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(userid); var strSql = new StringBuilder(); strSql.Append("SELECT * from cw_currency_rate where ACCDATE like '" + strCwACCDATE.Trim().Substring(0, 4) + "%' and STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");// and CORPID='" + companyid + "' if (!string.IsNullOrEmpty(currency)) { strSql.Append(" and LINKGID in (select gid from code_currency where CODENAME='" + currency + "')"); } var list=SetData(strSql); if (list.Count > 0) return list[0]; return new MsCwCurrencyRate(); } 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()) { MsCwCurrencyRate data = new MsCwCurrencyRate(); #region Set DB data to Object data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码 data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//货币GID data.ACCDATE = (reader["ACCDATE"] == null ? "" : Convert.ToString(reader["ACCDATE"]));//会计期间 data.BEGRATE = (reader["BEGRATE"] == null ? 0 : Convert.ToDecimal(reader["BEGRATE"]));//期初汇率 data.ENDRATE = (reader["ENDRATE"] == null ? 0 : Convert.ToDecimal(reader["ENDRATE"]));//期末汇率 data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司GID data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人GID if (reader["CREATETIME"] != null && reader["CREATETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CREATETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CREATETIME"].ToString().Trim() != "") { data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间 } data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//最后一次更改操作人GID if (reader["MODIFIEDTIME"] != null && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME"].ToString().Trim() != "") { data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更改操作时间 } data.ISDELETE = (reader["ISDELETE"] == null ? false : Convert.ToBoolean(reader["ISDELETE"]));//是否删除 data.DELETEUSER = (reader["DELETEUSER"] == null ? "" : Convert.ToString(reader["DELETEUSER"]));//删除人GID if (reader["DELETETIME"] != null && reader["DELETETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["DELETETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["DELETETIME"].ToString().Trim() != "") { data.DELETETIME = Convert.ToDateTime(reader["DELETETIME"]);//删除时间 } data.STARTGID = (reader["STARTGID"] == null ? "" : Convert.ToString(reader["STARTGID"]));//总账已启用已登录账套GID #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 判断本年是否有符合条件的默认模板数据 public static void isSaveRow(string currency, string userid, string companyid) { string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid); string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(userid); if (strCwACCDATE != "") { string strYEAR = DateTime.Parse(strCwACCDATE + "-01").Year.ToString(); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); string CurrencyGID = T_ALL_DA.GetStrSQL("GID", "select top 1 gid from code_currency where CODENAME='" + currency + "'"); int icount = int.Parse(T_ALL_DA.GetStrSQL("icount", "select count(*) as icount from cw_currency_rate where LINKGID='" + CurrencyGID + "' and SUBSTRING(ACCDATE,1,4)='" + strYEAR + "' and STARTGID='" + strCwSTARTGID + "'")); if (icount == 0) { //获取参数 SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@strYEAR",SqlDbType.VarChar,7), new SqlParameter("@currency",SqlDbType.VarChar,10), new SqlParameter("@CurrencyGID",SqlDbType.VarChar,36), new SqlParameter("@userid",SqlDbType.VarChar,36), new SqlParameter("@companyid",SqlDbType.VarChar,36), new SqlParameter("@STARTGID",SqlDbType.VarChar,36) }; parms[0].Value = strYEAR; parms[1].Value = currency; parms[2].Value = CurrencyGID; parms[3].Value = userid; parms[4].Value = companyid; parms[5].Value = strCwSTARTGID; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int iResult = SqlHelper.ExecuteSqlStoredProcedureReturn(conn, "proc_isCwCurrencyRate", parms); } } } } #endregion } }