Beispiel #1
0
        public void InsertTest()
        {
            LineDataProvider  _provider = new LineDataProvider();
            double            count     = 0;
            List <string>     ipList    = new IPHelper().GetIPListFromStartHost("192.167.1.1", 20, out count);
            List <OrganModel> organList = new List <OrganModel>();
            List <LineModel>  lineList  = new List <LineModel>();
            double            x         = 0;
            double            y         = 0;
            int    j = 0;
            Random r = new Random();

            for (int i = 0; i < 1000; i++)
            {
                x = r.Next(-200, 200) * 0.1;
                y = r.Next(-200, 200) * 0.1;
                organList.Add(new OrganModel()
                {
                    Name = "数据中心" + i, Description = i.ToString(), ParentId = 43, X = x.ToString(), Y = y.ToString()
                });
            }
            new OrganDataProvider().Insert(organList);

            List <OrganModel> newOrganList = new OrganDataProvider().GetAllItems("", "", "");

            foreach (var item in ipList)
            {
                j = r.Next(43, 1000);
                lineList.Add(new LineModel()
                {
                    AlarmMax = 3, Description = item, LineIP = item, OrganizationId = newOrganList[j].Id, LineType = LineType.mainline, PingInterval = 30, Pingsize = 32, Pingtimes = 4, ServiceProvider = ServiceProviderType.ChinaMobile, Timeout = 2, Name = item
                });
            }
            _provider.Insert(lineList);
        }
Beispiel #2
0
        public LineModel Insert(LineModel model)
        {
            var    item      = _provider.GetItem(" AND Name=@Name", new { Name = model.Name });
            string baseSql   = "INSERT INTO tb_line(Name,Description,LineIP,OrganizationId,LineType,ServiceProvider,{0})VALUES(@Name,@Description,@LineIP,@OrganizationId,@LineType,@ServiceProvider,{1})";
            string sql       = "INSERT INTO tb_line(Name,Description,LineIP,OrganizationId,LineType,ServiceProvider)VALUES(@Name,@Description,@LineIP,@OrganizationId,@LineType,@ServiceProvider)";
            string field     = string.Empty;
            string parameter = string.Empty;

            if (item != null)
            {
                throw new Exception("已存在相同用户名的用户");
            }

            if (model.Pingtimes != 0)
            {
                field     += "Pingtimes,";
                parameter += "@Pingtimes,";
            }
            if (model.Pingsize != 0)
            {
                field     += "Pingsize,";
                parameter += "@Pingsize,";
            }
            if (model.Timeout != 0)
            {
                field     += "Timeout,";
                parameter += "@Timeout,";
            }
            if (model.PingInterval != 0)
            {
                field     += "PingInterval,";
                parameter += "@PingInterval,";
            }
            if (model.AlarmMax != 0)
            {
                field     += "AlarmMax,";
                parameter += "@AlarmMax,";
            }

            //string.Format(baseSql, field.Substring(0, field.Length - 1), parameter.Substring(0, parameter.Length - 1));
            var insertsql = field.Length > 0 ? string.Format(baseSql, field.Substring(0, field.Length - 1), parameter.Substring(0, parameter.Length - 1)) : sql;
            int id        = _provider.Insert(insertsql, model);

            return(GetItem(id));
        }