Ejemplo n.º 1
1
		public void Reload (IDB db)
		{
			if (id <= 0)
				throw new ArgumentException ("There's no id to reload from.");

			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "SELECT * FROM " + Table + " WHERE id = " + id.ToString ();
				using (IDataReader reader = cmd.ExecuteReader ()) {
					if (!reader.Read ())
						throw new Exception ("No records found");

					Load (reader);

					if (reader.Read ())
						throw new Exception ("More than one record found.");
				}
			}
		}
Ejemplo n.º 2
0
 internal MainServiceImpl(PlayerAuth auth, IDB db, SingleThreadScheduler in_memory_worker, IMatchMaker match_maker)
 {
     this.db               = db;
     this.auth             = auth;
     this.in_memory_worker = in_memory_worker;
     this.match_maker      = match_maker;
 }
Ejemplo n.º 3
0
        Dictionary <TKey, List <TValue> > IDB.ExecuteToDicS <TKey, TValue>(string sql, string key_name, string value_name, IDbDataParameter[] pars)
        {
            IDB db = this;
            var dt = db.ExecuteToTable(sql, pars);

            Dictionary <TKey, List <TValue> > dic = new Dictionary <TKey, List <TValue> >();

            foreach (DataRow dr in dt.Rows)
            {
                var Key   = (TKey)Convert.ChangeType(dr[key_name], typeof(TKey));
                var Value = (List <TValue>)Convert.ChangeType(dr[value_name], typeof(TValue));
                if (dic.TryGetValue(Key, out Value))
                {
                    foreach (var item in Value)
                    {
                        dic[Key].Add(item);
                    }
                }
                else
                {
                    dic.Add(Key, Value);
                }
            }

            return(dic);
        }
Ejemplo n.º 4
0
        public IDB DoConfig()
        {
            IDB Config = null;

            if (String.IsNullOrEmpty(txt_Path.Text))
            {
                SetError(txt_Path, "文件路径不能为空");
                return(Config);
            }

            DB_SQLite tmp = new DB_SQLite()
            {
                DataSource = txt_Path.Text,
                password   = txt_Pwd.Text
            };

            try
            {
                var fac = System.Data.Common.DbProviderFactories.GetFactory(tmp.ProviderName);

                using (var conn = fac.CreateConnection())
                {
                    conn.ConnectionString = tmp.GetConnectionStr();
                    conn.Open();
                    conn.Close();
                    Config = tmp;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(Config);
        }
        public static async Task <IActionResult> Run([Inject] IDB fakeDB,
                                                     [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
                                                     ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = null;

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            log.LogInformation("request body", requestBody);
            dynamic data = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            if (name != null)
            {
                log.LogInformation("name", name);
                var product = fakeDB.CreateProduct(name);
                var json    = JsonConvert.SerializeObject(new
                {
                    product = product
                });
                return((ActionResult) new OkObjectResult(json));
            }
            else
            {
                return(new BadRequestObjectResult("Missing name in posted Body"));
            }
        }
Ejemplo n.º 6
0
        DbConnection TestConnection()
        {
            DbConnection dbconn = null;

            try
            {
                dbconn = new DbConnection
                {
                    DbType   = this.ddlDBType.Text == "MySql" ? EDbType.MySql : EDbType.SqlServer,
                    Server   = this.txtServer.Text.Trim(),
                    Port     = int.Parse(this.txtPort.Text.Trim()),
                    User     = this.txtUserName.Text.Trim(),
                    Password = this.txtPassword.Text,
                };
                IDB db = dbconn.GetDB();
                db.TestConnection();

                MessageBox.Show("链接成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(dbconn);
        }
Ejemplo n.º 7
0
        //http://127.0.0.1:8888?model=test&action=getbyid&_id=5744a604f1fa4b04a82cb94a
        public static string getbyid(Message m)
        {
            string json = "{}";

            try
            {
                var    jobject = JsonConvert.DeserializeObject <JObject>(m.input);
                string id      = jobject.getValue(_LITEDB_CONST.FIELD_ID);

                if (id.Length == 24)
                {
                    IDB db = dbi.Get(m.model);
                    {
                        var result = db.FindById(id);
                        json = @"{""ok"":true,""total"":" + db.Count().ToString() + @",""count"":" + (result == null ? "0" : "1") + @", ""items"":" + (result == null ? "null" : result.toJson) + @"}";
                    }
                }
                else
                {
                    json = JsonConvert.SerializeObject(new { ok = false, output = "The field _id should be 24 hex characters" });
                }
            }
            catch (Exception ex)
            {
                json = JsonConvert.SerializeObject(new { ok = false, output = ex.Message });
            }
            return(json);
        }
Ejemplo n.º 8
0
        //UPDATE FUNCTIONS
        // Any function that has the same signature as the delegates can be passed as a parameter
        public static void UpdateRecord(IDB dbManager, UpdateSqlParamatersDelegate sqlDel, UpdateMySqlParamatersDelegate mySqlDel)
        {
            Console.WriteLine("Please enter an Id");
            int id = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Please enter a name");
            string name = Console.ReadLine();

            Console.WriteLine("Please enter an email");
            string email = Console.ReadLine();

            Console.WriteLine("Please enter a contact");
            string contact = Console.ReadLine();

            try
            {
                if (dbManager is SQLDbManager)
                {
                    // Where connection between delegate and local function is shown
                    List <SqlParameter> list = sqlDel(id, name, email, contact);
                    UpdateOneRecord <SqlParameter>(dbManager, list);
                }
                else if (dbManager is MySqlDbManager)
                {
                    List <MySqlParameter> list = mySqlDel(id, name, email, contact);
                    UpdateOneRecord <MySqlParameter>(dbManager, list);
                }
            }
            catch (Exception ex)
            {
                // Exception is handled
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 9
0
        //DELETE FUNCTIONS
        public static void DeleteRecord(IDB dbManager)
        {
            Console.WriteLine("Please enter a Id");
            int id = Convert.ToInt32(Console.ReadLine());

            try
            {
                if (dbManager is SQLDbManager)
                {
                    // Create a list of SQL parameter objects, here just with id
                    List <SqlParameter> list = new List <SqlParameter>
                    {
                        new SqlParameter("@Id", id)
                    };
                    DeleteOneRecord <SqlParameter>(dbManager, list);
                }

                else if (dbManager is MySqlDbManager)
                {
                    List <MySqlParameter> list = new List <MySqlParameter>
                    {
                        new MySqlParameter("IdVal", id)
                    };
                    DeleteOneRecord <MySqlParameter>(dbManager, list);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 10
0
        //http://127.0.0.1:8888/?model=test&action=fetch
        //http://127.0.0.1:8888/?model=test&action=fetch&skip=0&limit=10
        public static string fetch(Message m)
        {
            var    jobject = JsonConvert.DeserializeObject <JObject>(m.input);
            string json    = @"{""ok"":false,""total"":-1,""count"":-1,""msg"":""Can not find model [" + m.model + @"]""}";
            string skip    = jobject.getValue("skip");
            string limit   = jobject.getValue("limit");

            long _skip  = 0;
            long _limit = 0;

            long.TryParse(skip, out _skip);
            long.TryParse(limit, out _limit);

            if (_skip < 0)
            {
                _skip = _LITEDB_CONST._SKIP;
            }
            if (_limit <= 0)
            {
                _limit = _LITEDB_CONST._LIMIT;
            }

            IDB db = dbi.Get(m.model);

            if (db != null)
            {
                var result = db.Fetch(_skip, _limit).Select(x => x.toJson).ToArray();
                json = @"{""ok"":true,""total"":" + db.Count().ToString() + @",""count"":" + result.Length.ToString() + @",""items"":[" + string.Join(",", result) + @"]}";
            }
            return(json);
        }
Ejemplo n.º 11
0
        public static void InsertRecord(IDB dbManager)
        {
            Console.WriteLine("Please enter a name");
            string name = Console.ReadLine();

            Console.WriteLine("Please enter an email");
            string email = Console.ReadLine();

            Console.WriteLine("Please enter a contact");
            string contact = Console.ReadLine();

            if (dbManager is SQLDbManager)
            {
                // Bind our parameters to our list
                List <SqlParameter> list = new List <SqlParameter>
                {
                    new SqlParameter("@Name", name),
                    new SqlParameter("@Email", email),
                    new SqlParameter("@Contact", contact)
                };
                // Also a generic function that works for both SQL and MySQL
                InsertOneRecord <SqlParameter>(dbManager, list);
            }
            else if (dbManager is MySqlDbManager)
            {
                List <MySqlParameter> list = new List <MySqlParameter>
                {
                    new MySqlParameter("NameVal", name),
                    new MySqlParameter("EmailVal", email),
                    new MySqlParameter("ContactVal", contact)
                };
                InsertOneRecord <MySqlParameter>(dbManager, list);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 使用指定的参数初始化对象
 /// </summary>
 /// <param name="DB">负责和数据库进行通讯的对象</param>
 /// <param name="TableName">数据表的名称</param>
 /// <param name="PrimaryKeyName">主键的列名</param>
 /// <param name="PrimaryKey">主键的值</param>
 public DBBinding(IDB DB, string TableName, string PrimaryKeyName, object PrimaryKey)
 {
     this.DB             = DB;
     this.TableName      = TableName;
     this.PrimaryKeyName = PrimaryKeyName;
     this.PrimaryKey     = PrimaryKey;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Вставка записи
        /// </summary>
        public static void InsertRecord(IDB insertObject)
        {
            string tableName = String.Empty;

            if (insertObject is Employee employee)
            {
                employeeList.Add(employee);
                tableName = "Employee";
            }
            if (insertObject is Department department)
            {
                departmentList.Add(department);
                tableName = "Department";
            }

            if (String.IsNullOrEmpty(tableName))
            {
                return;
            }

            command = new SqlCommand(insertObject.InsertString(tableName), connection);
            command.ExecuteNonQuery();

            //временное решение, чтобы цеплялись id к новым записям
            departmentList.Clear();
            employeeList.Clear();
            FillLists();
        }
Ejemplo n.º 14
0
        public void Update_20181219()
        {
            DBByHandClose db = new DBByHandClose(Appsetting.conn);
            IDB           d  = db;

            try
            {
                db.Open();
                db.BeginTran();

                string sql = @"create table 测试升级(
	id varchar(20)
)";

                d.ExecuteScalar(sql, null);

                d.ExecuteScalar(" update sys_t_system set sys_var_value='" + Appsetting.versions + "'   where sys_var_id='app_ver' ", null);
                d.ExecuteScalar(" update sys_t_system set sys_var_value='" + Appsetting.versions + "'   where sys_var_id='ser_ver' ", null);
                d.ExecuteScalar(" update sys_t_system set sys_var_value='" + Appsetting.versions + "'   where sys_var_id='db_ver' ", null);

                db.CommitTran();
            }
            catch (Exception ex)
            {
                db.RollBackTran();
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }
Ejemplo n.º 15
0
 private void OnDestroy()
 {
     if (DB != null)
     {
         DB.Close();
         DB = null;
     }
 }
Ejemplo n.º 16
0
        internal PlayerAuth(LoginServerClientLL login_server, IDB db)
        {
            this.login_server = login_server;
            this.db           = db;

            login_server.OnDisconnected       += on_disconnected_from_server;
            login_server.OnPlayerDisconnected += on_player_disconnected;
        }
Ejemplo n.º 17
0
 public ParamsRelatedBackToDetector(string table, IDB db = null)
 {
     this.table = table;
     if (db != null)
         this.db = db;
     else
         this.db = new DB(false);
 }
Ejemplo n.º 18
0
 public AuthController(SignInManager <ApplicationUser> signInManager
                       , UserManager <ApplicationUser> userManager, IDB db, Microsoft.Extensions.Configuration.IConfiguration configuration)
 {
     _signInManager = signInManager;
     _userManager   = userManager;
     _db            = db;
     _configuration = configuration;
 }
Ejemplo n.º 19
0
        public LogicBase(IDB db)
        {
            DB = db;
            var tEntity = new TEntity();

            DefaultQuery = tEntity.DefaultQuery;
            TableName    = Util.GetTableName(typeof(TEntity));
        }
Ejemplo n.º 20
0
            public Descriptors(string table, IDB db = null)
			{
                if (db == null)
                    this.db = new DB();
                else
                    this.db = db;
                this.table = table;
			}
Ejemplo n.º 21
0
 public MainForm()
 {
     InitializeComponent();
       mainFormController = new Controllers.MainFormController(this);
       db = new DB();
       dbGenerator = new DBGenerator(this);
       //validator = new Validator(this);
 }
Ejemplo n.º 22
0
        public IDB DoConfig()
        {
            IDB Config = null;

            if (String.IsNullOrEmpty(txt_Server.Text))
            {
                txt_Server.ErrorText          = "服务器不能为空!";
                txt_Server.ErrorIconAlignment = ErrorIconAlignment.MiddleRight;
                return(null);
            }

            if (String.IsNullOrEmpty(txt_User.Text))
            {
                txt_User.ErrorText          = "用户名不能为空!";
                txt_User.ErrorIconAlignment = ErrorIconAlignment.MiddleRight;
                return(null);
            }

            if (String.IsNullOrEmpty(txt_Pwd.Text))
            {
                txt_Pwd.ErrorText          = "密码不能为空!";
                txt_Pwd.ErrorIconAlignment = ErrorIconAlignment.MiddleRight;
                return(null);
            }
            if (String.IsNullOrEmpty(txt_DataBase.Text))
            {
                txt_DataBase.ErrorText          = "数据库不能为空!";
                txt_DataBase.ErrorIconAlignment = ErrorIconAlignment.MiddleRight;
                return(null);
            }


            DB_Oracle tmp = new DB_Oracle()
            {
                HOST        = txt_Server.Text,
                ServiceName = txt_DataBase.Text,
                UserID      = txt_User.Text,
                Password    = txt_Pwd.Text
            };

            try
            {
                var fac = System.Data.Common.DbProviderFactories.GetFactory(tmp.ProviderName);

                using (var conn = fac.CreateConnection())
                {
                    conn.ConnectionString = tmp.GetConnectionStr();
                    conn.Open();
                    conn.Close();
                    Config = tmp;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(Config);
        }
Ejemplo n.º 23
0
        public RecipeService(IDB db)
        {
            _db = db;

            _mapper = new Mapper(
                new MapperConfiguration(
                    cfg => cfg
                    .AddProfile <RecipeProfile>()));
        }
Ejemplo n.º 24
0
        public DishService(IDB db)
        {
            _db = db;

            _mapper = new Mapper(
                new MapperConfiguration(
                    cfg => cfg
                    .AddProfile <DishProfile>()));
        }
Ejemplo n.º 25
0
        public OrderService(IDB db)
        {
            _db = db;

            _mapper = new Mapper(
                new MapperConfiguration(
                    cfg => cfg
                    .AddProfile <OrderProfile>()));
        }
Ejemplo n.º 26
0
        public BurgerRepository(IDB db, IServiceable <Ingredient> ingredientService)
        {
            _db = db;
            _ingredientService = ingredientService;
            _burgers           = new List <Burger>();

            GetBurgersFromDB();
            AddIngredients();
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Adds a base item to the project-file manager
 /// </summary>
 /// <param name="theme">The item to add</param>
 /// <returns>true, if successful - false, otherwise</returns>
 public bool AddDB(IDB db)
 {
     if (!DBs.Contains(db))
     {
         DBs.Add(db);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 28
0
        public IngredientService(IDB db)
        {
            _db = db;

            _mapper = new Mapper(
                new MapperConfiguration(
                    cfg => cfg
                    .AddProfile <IngredientProfile>()));
        }
Ejemplo n.º 29
0
 public Database(string projectName, RDBMS rdbms, IConfiguration configuration, ILogger <Database> logger)
 {
     this.projectName       = projectName;
     this.rdbms             = rdbms;
     this.configuration     = configuration;
     this.logger            = logger ?? throw new ArgumentNullException(nameof(logger));
     database               = GetDatabase(rdbms);
     connectionString       = GetConnectionStringFromConfig(connectionStringName);
     connectionStringMaster = GetConnectionStringFromConfig(connectionStringMasterName);
 }
Ejemplo n.º 30
0
        public void setDB(bool sandt)
        {
            var httpContext = Request.Properties["MS_HttpContext"] as System.Web.HttpContextWrapper;

            if (httpContext.Application["DB"] != null)
            {
                DB = (IDB)httpContext.Application["DB"];
            }
            httpContext.Application["DB"] = DB;
        }
Ejemplo n.º 31
0
            public ClousotWorker(CallLocalClousotMainFunc <Method, Assembly> callClousotMain, IWorkerId id, FList <string> baseArgs, IScheduler scheduler, ISimpleLineWriter output, IDB db)
                : base(id, baseArgs, scheduler)
            {
                Contract.Requires(id != null);


                this.callClousotMain = callClousotMain;
                this.output          = output;
                this.db = db;
            }
Ejemplo n.º 32
0
 public Context()
 {
     _database              = new SQLite_DB();
     _ingredientRepository  = new IngredientRepository(_database);
     _ingredientService     = new IngredientService(_ingredientRepository);
     _burgerRepository      = new BurgerRepository(_database, _ingredientService);
     _burgerService         = new BurgerService(_burgerRepository.GetAll());
     _refreshmentRepository = new RefreshmentRepository(_database);
     _refreshmentService    = new RefreshmentService(_refreshmentRepository);
 }
Ejemplo n.º 33
0
        private static long _total(string model)
        {
            IDB db = Get(model);

            if (db != null)
            {
                return(db.Count());
            }
            return(0);
        }
Ejemplo n.º 34
0
        public bool UpdateTbl(long id, string table, ElementList sParams, IDB db)
        {
            db.SetConnection();
            string sSQL1  = "UPDATE " + table + " SET ";
            string sSQL1i = String.Empty;
            string wh     = " where detector_id = " + id.ToString();
            string sSQL   = sSQL1 + sParams.ColumnEqValueList + wh;

            return(db.Execute(sSQL));
        }
Ejemplo n.º 35
0
 private void DlgImport_Load(object sender, EventArgs e)
 {
     db = new DB(this);
       try {
     newDevelopersTable = db.getNewDevelopers(fileName);
     dataGridView1.DataSource = newDevelopersTable;
       }
       catch (Exception ex) {
     MessageBox.Show(ex.Message);
     Close();
       }
 }
Ejemplo n.º 36
0
 private void fillGrid()
 {
     db = new DB(this);
       try {
     newFieldsTable = db.getNewFields(wizard.FileName);
     newFieldsTable.Columns["Field"].ReadOnly = true;
     dataGridView1.DataSource = newFieldsTable;
       }
       catch (Exception ex) {
     MessageBox.Show(ex.Message);
     Close();
       }
 }
Ejemplo n.º 37
0
 public LMAcquireParams(IDB x)
 {
     db = x;
 }
Ejemplo n.º 38
0
 public AcquireParams()
 {
     db = new DB2(true);
 }
Ejemplo n.º 39
0
 public AlphaBeta(IDB db = null)
     : base("alpha_beta_rec", db)
 {
 }
Ejemplo n.º 40
0
		public override void Save (IDB db)
		{
			throw new Exception ("Can't save a View");
		}
Ejemplo n.º 41
0
 public AcquireParams(IDB db)
 {
     this.db = db;
 }
Ejemplo n.º 42
0
 public bool UpdateTbl(long id, string table, ElementList sParams, IDB db) 
 {
     db.SetConnection();
     string sSQL1 = "UPDATE " + table + " SET ";
     string sSQL1i = String.Empty;
     string wh = " where detector_id = " + id.ToString();
     string sSQL = sSQL1 + sParams.ColumnEqValueList + wh;
     return db.Execute(sSQL);
 }
Ejemplo n.º 43
0
 public LMMultiplicityParams(IDB db = null)
     : base("LMMultiplicity", db)
 {
 }
Ejemplo n.º 44
0
 public ShiftRegisterParams2(IDB db = null)
     : base("sr_parms_rec", db)
 {
 }
Ejemplo n.º 45
0
 public ShiftRegisterParams(bool newid = false)
 {
     db = new DB(false);
     Id = newid;
 }
Ejemplo n.º 46
0
 public SRParamsExtension(IDB db = null)
     : base("sr_parms_ext", db)
 {
 }
Ejemplo n.º 47
0
 private void fillGrid()
 {
     db = new DB();
       try {
     chkImport.Checked = true;
     newDevelopersTable = db.getNewDevelopers(wizard);
     dataGridView1.DataSource = newDevelopersTable;
       }
       catch (Exception ex) {
     MessageBox.Show(ex.Message);
     Close();
       }
 }
Ejemplo n.º 48
0
 public long CreateCfg(long id, ElementList sParams, IDB db) 
 {
     return CreateTbl(id, "LMHWParams", sParams, db);
 }
Ejemplo n.º 49
0
 public Detectors(IDB existing)
 {
     db = existing;
 }
Ejemplo n.º 50
0
 public LMNetCommParams(IDB _db)
 {
     db = _db;
 }
Ejemplo n.º 51
0
 public Detectors()
 {
     db = new DB(false);
 }
Ejemplo n.º 52
0
 public LMNetCommParams()
 {
     db = new DB(false);
 }
Ejemplo n.º 53
0
        private void fillGrid()
        {
            db = new DB();
              try
              {
            chkImport.Checked = true;
            newIsoReportTable = db.getNewIsoReports(wizard);
            foreach (DataColumn column in newIsoReportTable.Columns)
              column.ReadOnly = true;
            newIsoReportTable.Columns[DB.IMPORT].ReadOnly = false;
            dataGridView1.DataSource = newIsoReportTable;

              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            Close();
              }
        }
Ejemplo n.º 54
0
 public ShiftRegisterParams(IDB _db, bool newid = false)
 {
     db = _db;
     Id = newid;
 }
Ejemplo n.º 55
0
 public bool UpdateCfg(long id, ElementList sParams, IDB db) 
 {
     return UpdateTbl(id, "LMHWParams", sParams, db);
 }
Ejemplo n.º 56
0
 public bool UpdateNetComm(long id, ElementList sParams, IDB db) 
 {
     return UpdateTbl(id, "LMNetComm", sParams, db);
 }
Ejemplo n.º 57
0
 public long CreateNetComm(long id, ElementList sParams, IDB db) 
 {
     return CreateTbl(id, "LMNetComm", sParams, db);
 }
Ejemplo n.º 58
0
		public override void Delete (IDB db)
		{
			throw new Exception ("Can't delete a View");
		}
Ejemplo n.º 59
0
 private string ResolvedKey(string val, IDB _db)
 {
     Detectors dets = new Detectors(_db);
     if (Id)
     {
         long l = dets.PrimaryKey(val);
         return Field + "=" + l.ToString();
     }
     else
     {
         return Field + "=" + SQLSpecific.Value(val, true);   
     }
 }
Ejemplo n.º 60
0
 public long CreateTbl(long id, string table, ElementList sParams, IDB db) 
 {
     sParams.Add(new Element("detector_id", id));
     string sSQL1 = "Insert into " + table + " ";
     string sSQL = sSQL1 + sParams.ColumnsValues;
     
     ArrayList sqlList = new ArrayList(); 
     sqlList.Add(sSQL);
     sqlList.Add(SQLSpecific.getLastID(table));
     return db.ExecuteTransactionID(sqlList);
 }