今天有一段代码,先是用程序实现。

闲来无聊,又用存储过程实现了一次。

程序中实现。

        /// <summary>
        /// 根据区域和用户名获取可访问的国家
        /// </summary>                        
        public DataTable GetCountry(string area,string user)
        {
            try
            {
                NHibernate.Engine.ISessionImplementor FactoryImpl = FrameWork.Repository.NHb.SessionBuilder.CreateSession().GetSessionImplementation();
                OracleCommand cmd = new OracleCommand();

                string strWhere1 = "1=1 ";
                string strWhere2 = "1=1 ";

                if (!String.IsNullOrEmpty(user))
                {
                    strWhere1 += String.Format( "and vrs.u_logname = '{0}'",user);
                }

                if (!String.IsNullOrEmpty(area))
                {
                    strWhere2 += String.Format("and cc.sales_area = '{0}'", area);
                }
                string sqlstr =String.Format( @"select distinct scg.customer_country,cc.sales_area,cc.countrye,cc.countryc
                                  from ifce.vw_rsh_user              vru,
                                       ele_bill.sap_customer_general scg,
                                       shipuser.countryce            cc
                                 where vru.sap_cust_no = scg.customer_number
                                   and scg.customer_country = cc.short_e
                                   and vru.u_loginid in
                                       (select column_value countryId
                                          from table(splitstr_fun((select vrs.u_loginid || ',' ||
                                                                         vrs.agent_user_id
                                                                    from ifce.vw_rsh_user vrs
                                                                   where {0}),
                                                                  ',')))
                                   and {1}", strWhere1, strWhere2);

                cmd.Parameters.Clear();

                OracleConnection conn = (OracleConnection)FactoryImpl.Connection;
                cmd.Connection = conn;
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = sqlstr;
                cmd.ExecuteNonQuery();

                OracleDataAdapter da = new OracleDataAdapter(cmd);
                System.Data.DataSet ds = new System.Data.DataSet();
                da.Fill(ds);
                return ds.Tables[0];
            }
            catch (Exception e)
            {
                throw new FrameWork.THrException("Fail!", e);
            }
        }
View Code

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2021-12-23
  • 2021-08-21
  • 2021-12-05
  • 2021-04-09
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-12-06
  • 2021-07-19
相关资源
相似解决方案