コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public long ExecuteUpdate(UpdateCommandConfig UpCmdConfig)
        {
            DbNetData db = dbp.GetObject();

            try
            {
                long r = db.ExecuteUpdate(UpCmdConfig);
                return(r);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbp.PutObject(db);
            }
        }
コード例 #4
0
        public static UpdateCommandConfig PackUpdateCommandConfig(string sql, DataRow data, string[] keys)
        {
            UpdateCommandConfig CmdConfig = new UpdateCommandConfig(sql);

            foreach (DataColumn col in data.Table.Columns)
            {
                //if (data[col] != null)
                if (Array.IndexOf <string>(keys, col.ColumnName) >= 0)
                {
                    CmdConfig.FilterParams[col.ColumnName] = data[col];
                }
                else
                {
                    CmdConfig.Params[col.ColumnName] = data[col];
                }
            }
            return(CmdConfig);
        }
コード例 #5
0
        public void UpdateWithParam()
        {
            DbNetData db = GetDB();

            db.Open();
            string sql =
                @"update tblStation set stationOrdinal = @ori, stationName = @name, stationRemark=@remark, stationcpConfig=@cp
where stationid = @id";

            UpdateCommandConfig cmd = new UpdateCommandConfig(sql);

            cmd.Params.Add("id", 1);
            cmd.Params.Add("ori", 9);
            cmd.Params.Add("name", "name_param_up" + DateTime.Now.ToString());
            cmd.Params.Add("remark", "remark_param-up");
            cmd.Params.Add("cp", "cp_param_up");

            db.ExecuteScalar(cmd);
        }
コード例 #6
0
        public long?updateQuery(string query, ListDictionary parameters, ListDictionary filterParameters)
        {
            long?id = 0;

            try
            {
                UpdateCommandConfig command = new UpdateCommandConfig(query);
                command.Params             = parameters;
                command.FilterParams       = filterParameters;
                db.AllowUnqualifiedUpdates = true;
                id = db.ExecuteUpdate(command);
                db.Transaction.Commit();
                return(id);
            }
            catch (Exception ex)
            {
                if (db.Conn.State == ConnectionState.Open)
                {
                    db.Transaction.Rollback();
                }
                UDLA.FLUJOS.PASANTIAS.Comun.Logger.ExLogger(ex);
            }
            return(null);
        }
コード例 #7
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);
            }
        }
コード例 #8
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);
            }
        }