Exemplo n.º 1
0
        private void AddSearchTokenFilter(QueryCommandConfig query)
        {
            if (string.IsNullOrWhiteSpace(_DbNetGridConfiguration.SearchToken))
            {
                return;
            }

            var filter = new List <string>();

            foreach (DbColumn column in _DbNetGridConfiguration.Columns)
            {
                if (column.SimpleSearch)
                {
                    filter.Add($"{StripColumnRename(column.ColumnExpression)} like {Db.ParameterName("simplesearchtoken")}");
                }
            }

            if (filter.Any() == false)
            {
                return;
            }

            query.Sql += $" where ({string.Join(" or ", filter)})";
            query.Params["simplesearchtoken"] = $"%{_DbNetGridConfiguration.SearchToken}%";
        }
Exemplo n.º 2
0
        public static void CalXsVegdata(string gs_guid, string xs_guid, ref VegData vegdata, DbNetDataProxy db)
        {
            decimal packweight = 1;

            string key = string.Concat(gs_guid, xs_guid, vegdata.Vegname);

            if (!packDic.ContainsKey(key))
            {
                QueryCommandConfig qry = new QueryCommandConfig("select cfgdata from t_lk_chcfg where xs_guid = @xs_guid limit 1");
                qry.Params["xs_guid"] = xs_guid;
                object cfg = db.ExecuteScalar(qry);
                if (cfg != null)
                {
                    DataTable cfgDt = Rest.PackOrb.JsonToObj <DataTable>(cfg.ToString());
                    foreach (DataRow cfgR in cfgDt.Rows)
                    {
                        packDic.Add(string.Concat(gs_guid, xs_guid, cfgR.Field <string>("vegname")), Convert.ToDecimal(cfgR["packweight"]));
                        if (cfgR.Field <string>("vegname").Equals(vegdata.Vegname))
                        {
                            packweight = Convert.ToDecimal(cfgR["packweight"]);
                        }
                    }
                }
            }
            else
            {
                packweight = packDic[key];
            }

            vegdata.Amount    = decimal.Round(vegdata.Amount * packweight, 3);
            vegdata.Totalcost = vegdata.Totalcost;
            vegdata.Unitcost  = decimal.Round(vegdata.Unitcost / packweight, 3);
        }
Exemplo n.º 3
0
        private DataTable getCfgData()
        {
            DataTable dt  = null;
            string    key = string.Concat(gs_guid, xs_guid);

            if (cfgDataDic.ContainsKey(key))
            {
                dt = cfgDataDic[key];
            }
            else
            {
                string             addLk = "";
                QueryCommandConfig qry   = new QueryCommandConfig();
                if (!string.IsNullOrWhiteSpace(gs_guid))
                {
                    addLk = "and lk_guid in (select org_guid from t_org_reginfo where super_guid = @gs_guid and org_type = 2)";
                    qry.Params["gs_guid"] = gs_guid;
                }
                qry.Sql = string.Format("select cfgdata from t_lk_chcfg where xs_guid = @xs_guid {0}", addLk);
                qry.Params["xs_guid"] = xs_guid;
                dt = db.GetDataTable(qry);
                cfgDataDic.Add(key, dt);
            }

            return(dt);
        }
Exemplo n.º 4
0
        private int getVegunit(string gs_guid, string xs_guid)
        {
            if (this.vegunit != 0)
            {
                return(this.vegunit);
            }
            else
            {
                try
                {
                    QueryCommandConfig qry = new QueryCommandConfig("select vegunit from t_org_reginfo where org_guid = @xs_guid");
                    qry.Params["xs_guid"] = xs_guid;
                    object vegunitObj = db.ExecuteScalar(qry);
                    if (vegunitObj == null)
                    {
                        return(1);
                    }
                    else
                    {
                        this.vegunit = int.Parse(vegunitObj.ToString());
                        return(this.vegunit);
                    }
                }
                catch (Exception ex)
                {
                    DC.DCLogger.LogError(ex.Message);
                }
            }

            return(1);
        }
Exemplo n.º 5
0
        public static string CalZonestr(int zoneid, DbNetDataProxy db)
        {
            if (!zoneStrDic.ContainsKey(zoneid))
            {
                string        sql      = null;
                int[]         matchs   = null;
                List <string> zoneList = new List <string>();

                matchs = new int[] { zoneid, 1000 * (int)Math.Floor(zoneid / 1000d), 100000 * (int)Math.Floor(zoneid / 100000d), 10000000 * (int)Math.Floor(zoneid / 10000000d) };

                sql = string.Format("select * from t_dic_zone where zoneid in ({0}) order by zoneid", string.Join(",", matchs));
                QueryCommandConfig CmdConfig = new QueryCommandConfig(sql);
                DataTable          dt        = db.GetDataTable(CmdConfig);

                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow r in dt.Rows)
                    {
                        zoneList.Add(r.Field <string>("zonename"));
                    }
                }

                zoneStrDic.Add(zoneid, string.Join("-", zoneList));
            }

            return(zoneStrDic[zoneid]);
        }
Exemplo n.º 6
0
        public DataTable GetQuery(string query, string countQuery, ListDictionary parameters, out int aux)
        {
            aux = 0;
            try
            {
                QueryCommandConfig Query = new QueryCommandConfig(countQuery);
                Query.Params = parameters;
                db.ExecuteSingletonQuery(Query);
                var count = (int?)db.ReaderValue(0);
                if (count.HasValue)
                {
                    aux = count.Value;
                }
                QueryCommandConfig queryCmd = new QueryCommandConfig(query);
                queryCmd.Params             = parameters;
                db.ReturnAutoIncrementValue = true;


                var d = db.GetDataTable(queryCmd);
                db.Transaction.Commit();
                return(d);
            }
            catch (Exception ex)
            {
                if (db.Conn.State == ConnectionState.Open)
                {
                    db.Transaction.Rollback();
                }
                UDLA.FLUJOS.PASANTIAS.Comun.Logger.ExLogger(ex);
            }
            return(null);
        }
Exemplo n.º 7
0
Arquivo: DBIBase.cs Projeto: wpmyj/c3
 public DataTable ExecuteDataTable(QueryCommandConfig cmd)
 {
     using (DbNetData db = CreateDbNetData())
     {
         DataTable tbl = db.GetDataTable(cmd);
         return(tbl);
     }
 }
Exemplo n.º 8
0
 private void AddOrderBy(QueryCommandConfig query)
 {
     if (string.IsNullOrEmpty(_DbNetGridConfiguration.OrderByColumn))
     {
         _DbNetGridConfiguration.OrderByColumn   = _DbNetGridConfiguration.Columns.First().ColumnName;
         _DbNetGridConfiguration.OrderBySequence = "asc";
     }
     query.Sql += $" order by {_DbNetGridConfiguration.OrderByColumn} {_DbNetGridConfiguration.OrderBySequence}";
 }
Exemplo n.º 9
0
        private void AddDropDownFilter(QueryCommandConfig query)
        {
            if (string.IsNullOrWhiteSpace(_DbNetGridConfiguration.DropDownFilterValue))
            {
                return;
            }

            query.Sql += $"{(query.Sql.Contains(" where ") ? " and " : " where ")}({_DbNetGridConfiguration.DropDownFilterColumn} = {Db.ParameterName("DropDownFilterValue")})";
            query.Params["DropDownFilterValue"] = $"{_DbNetGridConfiguration.DropDownFilterValue}";
        }
Exemplo n.º 10
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();
                db.BeginTransaction();

                Dictionary <string, VegunitTrans> vtDic = new Dictionary <string, VegunitTrans>();
                QueryCommandConfig XsQry = new QueryCommandConfig("select * from t_xs_wdat_xsmx where recdate >= @startdate and recdate <= @enddate and amount=kilo");
                XsQry.Params["startdate"] = DateTime.Now.AddDays(-30);
                XsQry.Params["enddate"]   = DateTime.Now;
                DataTable xsDt = db.GetDataTable(XsQry);

                foreach (DataRow r in xsDt.Rows)
                {
                    string xs_guid = Convert.ToString(r["xs_guid"]);
                    if (!vtDic.ContainsKey(xs_guid))
                    {
                        vtDic.Add(xs_guid, new VegunitTrans(null, xs_guid.ToString(), dbp));
                    }
                    VegunitTrans vt = vtDic[xs_guid];

                    UpdateCommandConfig upd = new UpdateCommandConfig("t_xs_wdat_xsmx");
                    upd.FilterParams["recid"]   = r["recid"];
                    upd.FilterParams["recdate"] = r["recdate"];
                    upd.FilterParams["gs_guid"] = r["gs_guid"];
                    upd.FilterParams["xs_guid"] = r["xs_guid"];
                    upd.FilterParams["vegname"] = r["vegname"];

                    upd.Params["kilo"] = vt.CalWeight(Convert.ToString(r["vegname"]), Convert.ToDecimal(r["amount"]));

                    db.ExecuteUpdate(upd);
                }
                db.Commit();

                DC.DCLogger.LogTrace("Job successed [Job_GenerateXsmxKilo]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_GenerateXsmxKilo]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }
Exemplo n.º 11
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();

                QueryCommandConfig qry = new QueryCommandConfig("select adv_id,adv_date,adv_cate,attachments from t_adv_vegsad where adv_date > @startdate and approved = 1 and dealed != 1");
                qry.Params["startdate"] = DateTime.Now.AddDays(-4);
                DataTable dt = db.GetDataTable(qry);

                if (dt.Rows.Count > 0)
                {
                    db.BeginTransaction();
                    Random ran = new Random();
                    //do market_xs
                    foreach (DataRow r in dt.Rows)
                    {
                        CommandConfig updCmd = new CommandConfig("update t_adv_vegsad set readcount_fake = readcount_fake + @add where adv_cate=@adv_cate and adv_id=@adv_id and adv_date=@adv_date");
                        updCmd.Params["adv_cate"] = r["adv_cate"];
                        updCmd.Params["adv_id"]   = r["adv_id"];
                        updCmd.Params["adv_date"] = r["adv_date"];
                        if (r["attachments"] != DBNull.Value && r["attachments"].ToString().Length > 0)
                        {
                            updCmd.Params["add"] = ran.Next(4);
                        }
                        else
                        {
                            updCmd.Params["add"] = ran.Next(2);
                        }
                        db.ExecuteNonQuery(updCmd);
                    }

                    db.Commit();
                }

                DC.DCLogger.LogTrace("Job successed [Job_AddAdvReadcount]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_AddAdvReadcount]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }
Exemplo n.º 12
0
        public static void CalXsVegdata(string gs_guid, string xs_guid, ref DataTable vegdata, DbNetDataProxy db)
        {
            QueryCommandConfig qry = new QueryCommandConfig("select vegunit from t_org_reginfo where org_guid = @xs_guid");

            qry.Params["xs_guid"] = xs_guid;
            object vegunitObj = db.ExecuteScalar(qry);

            if (vegunitObj == null)
            {
                return;
            }

            int vegunit = int.Parse(vegunitObj.ToString());

            if (vegunit != 2)
            {
                return;
            }

            string vegname  = "vegname";
            string amount   = "amount";
            string unitcost = "unitcost";

            if (vegdata.Columns.Contains("unitprice"))
            {
                unitcost = "unitprice";
            }
            string totalcost = "totalcost";

            if (vegdata.Columns.Contains("totalprice"))
            {
                totalcost = "totalprice";
            }

            if (vegdata != null && vegdata.Rows.Count > 0)
            {
                foreach (DataRow r in vegdata.Rows)
                {
                    VegData vd = new VegData {
                        Vegname = r.Field <string>(vegname), Amount = r.Field <decimal>(amount), Unitcost = r.Field <decimal>(unitcost), Totalcost = r.Field <decimal>(totalcost)
                    };
                    CalXsVegdata(gs_guid, xs_guid, ref vd, db);
                    r[amount]    = vd.Amount;
                    r[unitcost]  = vd.Unitcost;
                    r[totalcost] = vd.Totalcost;
                }
            }
        }
Exemplo n.º 13
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();
                db.BeginTransaction();

                QueryCommandConfig xsQry = new QueryCommandConfig("select org_guid from t_org_reginfo where org_type =3");
                DataTable          xsDt  = db.GetDataTable(xsQry);

                foreach (DataRow r in xsDt.Rows)
                {
                    QueryCommandConfig vegQry = new QueryCommandConfig("select vegname,amount from t_xs_wdat_kc where xs_guid = @xs_guid");
                    vegQry.Params["xs_guid"] = r["org_guid"];
                    DataTable vegDt = dbp.GetDataTable(vegQry);

                    if (vegDt.Rows.Count > 0)
                    {
                        var vegEnum = from veg in vegDt.AsEnumerable() orderby veg.Field <decimal>("amount") descending select veg.Field <string>("vegname");

                        UpdateCommandConfig xskcUpd = new UpdateCommandConfig("t_org_reginfo");
                        xskcUpd.FilterParams["org_guid"] = r["org_guid"];
                        xskcUpd.Params["business"]       = string.Join("|", vegEnum);
                        db.ExecuteUpdate(xskcUpd);
                    }
                }
                db.Commit();

                DC.DCLogger.LogTrace("Job successed [Job_GenerateXsBusiness]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_GenerateXsBusiness]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }
Exemplo n.º 14
0
        public object GetSingleQuery(string query, ListDictionary parameters)
        {
            try
            {
                QueryCommandConfig Query = new QueryCommandConfig(query);
                Query.Params = parameters;
                db.ExecuteSingletonQuery(Query);
                return(db.ReaderValue(0));

                db.Transaction.Commit();
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                UDLA.FLUJOS.PASANTIAS.Comun.Logger.ExLogger(ex);
            }
            return(null);
        }
Exemplo n.º 15
0
 public void ExecuteGenericQuery(string query, ListDictionary parameters)
 {
     try
     {
         QueryCommandConfig queryCmd = new QueryCommandConfig(query);
         queryCmd.Params = parameters;
         db.ExecuteNonQuery(queryCmd);
         db.Transaction.Commit();
     }
     catch (Exception ex)
     {
         if (db.Conn.State == ConnectionState.Open)
         {
             db.Transaction.Rollback();
         }
         UDLA.FLUJOS.PASANTIAS.Comun.Logger.ExLogger(ex);
     }
 }
Exemplo n.º 16
0
        public DataTable GetDataTable(QueryCommandConfig CmdConfig)
        {
            DbNetData db = dbp.GetObject();

            try
            {
                DataTable r = db.GetDataTable(CmdConfig);
                return(r);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbp.PutObject(db);
            }
        }
Exemplo n.º 17
0
        public object ExecuteScalar(QueryCommandConfig QryCmd)
        {
            DbNetData db = dbp.GetObject();

            try
            {
                object r = db.ExecuteScalar(QryCmd);
                return(r);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbp.PutObject(db);
            }
        }
Exemplo n.º 18
0
        private void AddLookupData()
        {
            foreach (GridColumn gc in _DbNetGridConfiguration.Columns)
            {
                if (string.IsNullOrEmpty(gc.Lookup))
                {
                    continue;
                }
                QueryCommandConfig query = new QueryCommandConfig();
                query.Sql = gc.Lookup;
                Db.ExecuteQuery(query);

                while (Db.GetDataReader().Read())
                {
                    gc.LookupData[Db.ReaderString(0)] = Db.ReaderString(1);
                }
            }
        }
Exemplo n.º 19
0
        public static List <string> CalFuncset(string res_type, List <string> rolesetList, DbNetDataProxy db)
        {
            List <string>      funcset_List = new List <string>();
            QueryCommandConfig funcQryCmd   = new QueryCommandConfig(
                string.Format("select funcset from t_dic_resrole where res_type = @res_type and role_name in ('{0}')", string.Join("','", rolesetList)));

            funcQryCmd.Params["res_type"] = res_type;
            DataTable funcDt = db.GetDataTable(funcQryCmd);

            if (funcDt != null && funcDt.Rows.Count > 0)
            {
                foreach (DataRow r in funcDt.Rows)
                {
                    funcset_List = new List <string>(funcset_List.Union(r.Field <string>(0).Split('|')));
                }
                funcset_List.Sort();
            }

            return(funcset_List);
        }
Exemplo n.º 20
0
 public DataTable ExecuteQuery(string query, ListDictionary parameters)
 {
     try
     {
         QueryCommandConfig queryCmd = new QueryCommandConfig(query);
         queryCmd.Params             = parameters;
         db.ReturnAutoIncrementValue = true;
         var d = db.GetDataTable(queryCmd);
         db.Transaction.Commit();
         return(d);
     }
     catch (Exception ex)
     {
         if (db.Conn.State == ConnectionState.Open)
         {
             db.Transaction.Rollback();
         }
         UDLA.FLUJOS.PASANTIAS.Comun.Logger.ExLogger(ex);
     }
     return(null);
 }
Exemplo n.º 21
0
        private void GetPage()
        {
            string    Sql = $"select {ColumnList()} from {_DbNetGridConfiguration.TableName} where 1=2";
            DataTable dt  = Db.GetDataTable(Sql);

            QueryCommandConfig query = new QueryCommandConfig();

            query.Sql = $"select {ColumnList()} from {_DbNetGridConfiguration.TableName}";
            AddSearchTokenFilter(query);
            AddDropDownFilter(query);
            AddOrderBy(query);
            AddLookupData();

            int firstRecord   = (_DbNetGridConfiguration.PageSize * (_DbNetGridConfiguration.CurrentPage - 1)) + 1;
            int lastRecord    = (firstRecord + (_DbNetGridConfiguration.PageSize - 1));
            int recordCounter = 0;

            Db.ExecuteQuery(query);

            while (Db.GetDataReader().Read())
            {
                recordCounter++;
                if (recordCounter >= firstRecord && recordCounter <= lastRecord)
                {
                    DataRow row = dt.NewRow();

                    for (var i = 0; i < Db.GetDataReader().FieldCount; i++)
                    {
                        row[i] = Db.ReaderValue(i);
                    }


                    dt.Rows.Add(row);
                }
            }

            _DbNetGridConfiguration.TotalRows = recordCounter;
            _DbNetGridConfiguration.PageData  = dt;
        }
Exemplo n.º 22
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();
                db.BeginTransaction();

                //do market_xs
                QueryCommandConfig XsQry = new QueryCommandConfig("select sn,orgs,veg_hidden from t_dic_market_xs where orgs is not null and orgs !='' and veg_hidden is not null and veg_hidden !=''");
                DataTable          xsDt  = db.GetDataTable(XsQry);
                foreach (DataRow r in xsDt.Rows)
                {
                    List <string> orgs           = new List <string>(Convert.ToString(r["orgs"]).Split(','));
                    List <string> veg_hidden     = new List <string>(Convert.ToString(r["veg_hidden"]).Split(','));
                    List <string> veg_hidden_new = new List <string>(veg_hidden);

                    foreach (string veg in veg_hidden)
                    {
                        QueryCommandConfig xsmxQry = new QueryCommandConfig(string.Format("select count(*) from t_xs_wdat_xsmx where recdate >= @startdate and vegname = @vegname and xs_guid in ({0})", "'" + string.Join("','", orgs) + "'"));
                        xsmxQry.Params["startdate"] = DateTime.Now.AddDays(-3);
                        xsmxQry.Params["vegname"]   = veg;

                        int count = Convert.ToInt32(db.ExecuteScalar(xsmxQry));
                        if (count > 0)
                        {
                            veg_hidden_new.Remove(veg);
                        }
                    }

                    if (veg_hidden.Count > veg_hidden_new.Count)
                    {
                        UpdateCommandConfig upd = new UpdateCommandConfig("t_dic_market_xs");
                        upd.FilterParams["sn"] = r["sn"];

                        upd.Params["veg_hidden"] = string.Join(",", veg_hidden_new);

                        db.ExecuteUpdate(upd);
                    }
                }

                //do market_lk
                QueryCommandConfig LkQry = new QueryCommandConfig("select sn,orgs,veg_hidden from t_dic_market_lk where orgs is not null and orgs !='' and veg_hidden is not null and veg_hidden !=''");
                DataTable          lkDt  = db.GetDataTable(LkQry);
                foreach (DataRow r in lkDt.Rows)
                {
                    List <string> orgs           = new List <string>(Convert.ToString(r["orgs"]).Split(','));
                    List <string> veg_hidden     = new List <string>(Convert.ToString(r["veg_hidden"]).Split(','));
                    List <string> veg_hidden_new = new List <string>(veg_hidden);

                    foreach (string veg in veg_hidden)
                    {
                        QueryCommandConfig xsmxQry = new QueryCommandConfig(string.Format("select count(*) from t_lkdesk_wdat_jhd where Date >= @startdate and MerchandiseName = @vegname and lk_guid in ({0})", "'" + string.Join("','", orgs) + "'"));
                        xsmxQry.Params["startdate"] = DateTime.Now.AddDays(-3);
                        xsmxQry.Params["vegname"]   = veg;

                        int count = Convert.ToInt32(db.ExecuteScalar(xsmxQry));
                        if (count > 0)
                        {
                            veg_hidden_new.Remove(veg);
                        }
                    }

                    if (veg_hidden.Count > veg_hidden_new.Count)
                    {
                        UpdateCommandConfig upd = new UpdateCommandConfig("t_dic_market_lk");
                        upd.FilterParams["sn"] = r["sn"];

                        upd.Params["veg_hidden"] = string.Join(",", veg_hidden_new);

                        db.ExecuteUpdate(upd);
                    }
                }

                db.Commit();

                DC.DCLogger.LogTrace("Job successed [Job_DelMarketVeghidden]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_DelMarketVeghidden]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }
Exemplo n.º 23
0
        public static List <string> GetRegSet(string token, DbNetData db)
        {
            if (!regSetDic.ContainsKey(token))
            {
                List <string> regset = new List <string>();

                QueryCommandConfig qry = new QueryCommandConfig("select funcset,roleset from t_usr where login_token = @token");
                qry.Params["token"] = token;
                DataTable dt = db.GetDataTable(qry);
                if (dt.Rows.Count > 0)
                {
                    List <string> roleset = new List <string>();
                    if (dt.Rows[0].Field <string>("roleset") != null)
                    {
                        roleset = dt.Rows[0].Field <string>("roleset").Split('|').ToList();
                    }
                    List <string> funcset = new List <string>();
                    if (dt.Rows[0].Field <string>("funcset") != null)
                    {
                        funcset = dt.Rows[0].Field <string>("funcset").Split('|').ToList();
                    }
                    List <string> apiset = new List <string>();
                    if (roleset.Count > 0)
                    {
                        QueryCommandConfig qry2 = new QueryCommandConfig(string.Format("select funcset from t_dic_role where role_name in ({0})", "'" + string.Join("','", roleset) + "'"));
                        DataTable          fsdt = db.GetDataTable(qry2);
                        foreach (DataRow r in fsdt.Rows)
                        {
                            List <string> temp_funcset = r.Field <string>("funcset").Split('|').ToList();
                            funcset = funcset.Union(temp_funcset).ToList();
                        }
                    }
                    QueryCommandConfig qry3 = new QueryCommandConfig(string.Format("select apiset from t_dic_func where func_name in ({0})", "'" + string.Join("','", funcset) + "'"));
                    DataTable          asdt = db.GetDataTable(qry3);
                    foreach (DataRow r in asdt.Rows)
                    {
                        List <string> temp_apiset = r.Field <string>("apiset").Split('|').ToList();
                        apiset = apiset.Union(temp_apiset).ToList();
                    }
                    foreach (string apiurl in apiset)
                    {
                        regset.Add("^" + apiurl.Replace("*", "\\S+") + "$");
                    }
                }

                regSetDic.Add(token, regset);
                regSetTouch.Add(token, DateTime.Now);
            }
            else
            {
                regSetTouch[token] = DateTime.Now;
            }

            List <string> outTimeTokens = new List <string>();

            foreach (string key in regSetTouch.Keys)
            {
                if (DateTime.Now.Subtract(regSetTouch[token]).TotalMinutes > 60)
                {
                    outTimeTokens.Add(key);
                }
            }
            foreach (string key in outTimeTokens)
            {
                regSetDic.Remove(key);
                regSetTouch.Remove(key);
            }

            return(regSetDic[token]);
        }
Exemplo n.º 24
0
        private byte[] manage_register(string extInfo, byte[] req)
        {
            RegisterData para;

            byte[] checkResult = PackOrb.CheckRequest <RegisterData>(req, out para,
                                                                     new string[] {
                "MobileNumber",
                "Account",
                "Password",
            });
            if (checkResult != null)
            {
                return(checkResult);
            }
            if (!Regex.IsMatch(para.Account, "^[A-Za-z][A-Za-z0-9_]*$"))
            {
                return(PackOrb.PackRespose(
                           new HttpHeadInfo
                {
                    StatusCode = HttpStatusCode.BadRequest,
                },
                           new ListDictionary {
                    { "respnum", -1 },
                    { "respmsg", "帐号必须以英文字母开始,且只能由英文、数字和下划线组成" },
                }
                           ));
            }
            if (!Regex.IsMatch(para.MobileNumber, "^[0-9]*$"))
            {
                return(PackOrb.PackRespose(
                           new HttpHeadInfo
                {
                    StatusCode = HttpStatusCode.BadRequest,
                },
                           new ListDictionary {
                    { "respnum", -1 },
                    { "respmsg", "手机号必须以数字组成" },
                }
                           ));
            }

            #region 保存register信息

            long   ret     = 0;
            string mb_guid = Guid.NewGuid().ToString("N");
            try
            {
                QueryCommandConfig QryCmdConfig = new QueryCommandConfig("select count(*) from t_mobapp_reginfo where MobileNumber = @MobileNumber or Account = @Account");
                QryCmdConfig.Params["MobileNumber"] = para.MobileNumber;
                QryCmdConfig.Params["Account"]      = para.Account;
                object ob = db.ExecuteScalar(QryCmdConfig);
                if (ob != null && Int32.Parse(ob.ToString()) > 0)
                {
                    return(PackOrb.PackRespose(
                               new HttpHeadInfo
                    {
                        StatusCode = HttpStatusCode.BadRequest,
                    },
                               new ListDictionary {
                        { "respnum", -1 },
                        { "respmsg", "该手机号或帐号已注册" },
                    }
                               ));
                }
                CommandConfig CmdConfig = new CommandConfig("t_mobapp_reginfo");
                CmdConfig.Params["mb_guid"]      = mb_guid;
                CmdConfig.Params["MobileNumber"] = para.MobileNumber;
                CmdConfig.Params["Account"]      = para.Account;
                CmdConfig.Params["Password"]     = para.Password;
                ret -= db.ExecuteInsert(CmdConfig);
            }
            catch (Exception e)
            {
                DCLogger.LogError(e.Message);

                return(PackOrb.PackRespose(
                           new HttpHeadInfo
                {
                    StatusCode = HttpStatusCode.ServerSideError,
                },
                           new ListDictionary {
                    { "respnum", -2 },
                    { "respmsg", e.Message },
                }
                           ));
            }

            return(PackOrb.PackRespose(
                       new HttpHeadInfo
            {
                StatusCode = HttpStatusCode.Succeed,
            },
                       new ListDictionary {
                { "respnum", ret },
                { "respmsg", "用户注册成功" },
                { "mb_guid", mb_guid },
            }
                       ));

            #endregion
        }
Exemplo n.º 25
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();
                db.BeginTransaction();

                Dictionary <string, VegunitTrans> vtDic = new Dictionary <string, VegunitTrans>();
                QueryCommandConfig xskcQry = new QueryCommandConfig("select * from t_xs_wdat_kc");
                DataTable          xskcDt  = db.GetDataTable(xskcQry);

                foreach (DataRow r in xskcDt.Rows)
                {
                    string statSql = "SELECT vegname,date_format(recdate, '%Y-%m-%d') as date,round(max(totalprice/kilo),3) as max,round(min(totalprice/kilo),3) as min,round(avg(totalprice/kilo),3) as avg FROM t_xs_wdat_xsmx where recdate >= @startdate and recdate < @enddate and amount != kilo and vegname = @vegname and xs_guid in ({0}) group by vegname,date_format(recdate, '%Y-%m-%d')";

                    QueryCommandConfig statQry = new QueryCommandConfig(string.Format(statSql, "'" + r["xs_guid"] + "'"));
                    statQry.Params["startdate"] = DateTime.Now.Date.AddMonths(-6);
                    statQry.Params["enddate"]   = DateTime.Now.Date.AddDays(1);
                    statQry.Params["vegname"]   = r["vegname"];
                    DataTable statDt = dbp.GetDataTable(statQry);
                    if (statDt.Rows.Count > 0)
                    {
                        var result =
                            from statTbl in statDt.AsEnumerable()
                            orderby DateTime.Parse(statTbl.Field <string>("date")) descending
                                where DateTime.Parse(statTbl.Field <string>("date")) <= DateTime.Now.Date.AddDays(1)
                            select new ResponseData
                        {
                            max = statTbl.Field <decimal?>("max") ?? 0,
                            min = statTbl.Field <decimal?>("min") ?? 0,
                        };
                        decimal min = 0;
                        decimal max = 0;
                        foreach (ResponseData d in result)
                        {
                            if (d.max > 0 || d.min > 0)
                            {
                                min = d.min;
                                max = d.max;
                                break;
                            }
                        }
                        DataRow             statR   = statDt.Rows[0];
                        UpdateCommandConfig xskcUpd = new UpdateCommandConfig("t_xs_wdat_kc");
                        xskcUpd.FilterParams["xs_guid"] = r["xs_guid"];
                        xskcUpd.FilterParams["vegname"] = r["vegname"];
                        xskcUpd.Params["xs_price_min"]  = min;
                        xskcUpd.Params["xs_price_max"]  = max;
                        db.ExecuteUpdate(xskcUpd);
                    }
                }
                db.Commit();

                DC.DCLogger.LogTrace("Job successed [Job_CalXsgh]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_CalXsgh]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }
Exemplo n.º 26
0
        private byte[] dic_list(string extInfo, byte[] req)
        {
            DicListQry para;

            byte[] checkResult = PackOrb.CheckRequest <DicListQry>(req, out para,
                                                                   new string[] {
                "dicname",
            });
            if (checkResult != null)
            {
                return(checkResult);
            }

            #region 查询字典信息

            try
            {
                string dicTbl = null;
                switch (para.dicname)
                {
                case "蔬菜名称":
                    dicTbl = "t_dic_vegname";
                    break;

                case "蔬菜种类":
                    dicTbl = "t_dic_vegtype";
                    break;

                default:
                    return(PackOrb.PackRespose(
                               new HttpHeadInfo
                    {
                        StatusCode = HttpStatusCode.ServerSideError,
                    },
                               new ListDictionary {
                        { "respnum", -2 },
                        { "respmsg", "不存在此字典" },
                    }
                               ));
                }
                QueryCommandConfig CmdConfig = new QueryCommandConfig(string.Format("select * from {0} order by code", dicTbl));
                DataTable          dt        = db.GetDataTable(CmdConfig);

                return(PackOrb.PackRespose(
                           new HttpHeadInfo
                {
                    StatusCode = HttpStatusCode.Succeed,
                },
                           new ListDictionary {
                    { "respnum", dt.Rows.Count },
                    { "respmsg", "获取字典成功" },
                    { "count", dt.Rows.Count },
                    { "data", dt },
                }
                           ));
            }
            catch (Exception e)
            {
                DCLogger.LogError(e.Message);

                return(PackOrb.PackRespose(
                           new HttpHeadInfo
                {
                    StatusCode = HttpStatusCode.ServerSideError,
                },
                           new ListDictionary {
                    { "respnum", -2 },
                    { "respmsg", e.Message },
                }
                           ));
            }

            #endregion
        }
Exemplo n.º 27
0
        private byte[] manage_login(string extInfo, byte[] req)
        {
            ClientLogin para;

            byte[] checkResult = PackOrb.CheckRequest <ClientLogin>(req, out para,
                                                                    new string[] {
                "LoginName",
                "Password",
            });
            if (checkResult != null)
            {
                return(checkResult);
            }

            #region 登录验证

            try
            {
                string loginCol = "Account";
                if (Regex.IsMatch(para.LoginName, "^[0-9]*$"))
                {
                    loginCol = "MobileNumber";
                }
                QueryCommandConfig CmdConfig = new QueryCommandConfig(string.Format("select mb_guid,Password from t_mobapp_reginfo where {0} = @LoginName", loginCol));
                CmdConfig.Params["LoginName"] = para.LoginName;
                DataTable dt = db.GetDataTable(CmdConfig);
                if (dt.Rows.Count == 0)
                {
                    return(PackOrb.PackRespose(
                               new HttpHeadInfo
                    {
                        StatusCode = HttpStatusCode.BadRequest,
                    },
                               new ListDictionary {
                        { "respnum", -1 },
                        { "respmsg", "未找到此用户" },
                    }
                               ));
                }
                if (dt.Rows[0]["Password"].ToString().Equals(para.Password))
                {
                    return(PackOrb.PackRespose(
                               new HttpHeadInfo
                    {
                        StatusCode = HttpStatusCode.Succeed,
                    },
                               new ListDictionary {
                        { "respnum", 1 },
                        { "respmsg", "用户登录成功" },
                        { "mb_guid", dt.Rows[0]["mb_guid"].ToString() },
                    }
                               ));
                }
                else
                {
                    return(PackOrb.PackRespose(
                               new HttpHeadInfo
                    {
                        StatusCode = HttpStatusCode.BadRequest,
                    },
                               new ListDictionary {
                        { "respnum", -1 },
                        { "respmsg", "密码错误" },
                    }
                               ));
                }
            }
            catch (Exception e)
            {
                DCLogger.LogError(e.Message);

                return(PackOrb.PackRespose(
                           new HttpHeadInfo
                {
                    StatusCode = HttpStatusCode.ServerSideError,
                },
                           new ListDictionary {
                    { "respnum", -2 },
                    { "respmsg", e.Message },
                }
                           ));
            }

            #endregion
        }