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."); } } }
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; }
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); }
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")); } }
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); }
//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); }
//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); } }
//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); } }
//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); }
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); } }
/// <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; }
/// <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(); }
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(); } }
private void OnDestroy() { if (DB != null) { DB.Close(); DB = null; } }
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; }
public ParamsRelatedBackToDetector(string table, IDB db = null) { this.table = table; if (db != null) this.db = db; else this.db = new DB(false); }
public AuthController(SignInManager <ApplicationUser> signInManager , UserManager <ApplicationUser> userManager, IDB db, Microsoft.Extensions.Configuration.IConfiguration configuration) { _signInManager = signInManager; _userManager = userManager; _db = db; _configuration = configuration; }
public LogicBase(IDB db) { DB = db; var tEntity = new TEntity(); DefaultQuery = tEntity.DefaultQuery; TableName = Util.GetTableName(typeof(TEntity)); }
public Descriptors(string table, IDB db = null) { if (db == null) this.db = new DB(); else this.db = db; this.table = table; }
public MainForm() { InitializeComponent(); mainFormController = new Controllers.MainFormController(this); db = new DB(); dbGenerator = new DBGenerator(this); //validator = new Validator(this); }
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); }
public RecipeService(IDB db) { _db = db; _mapper = new Mapper( new MapperConfiguration( cfg => cfg .AddProfile <RecipeProfile>())); }
public DishService(IDB db) { _db = db; _mapper = new Mapper( new MapperConfiguration( cfg => cfg .AddProfile <DishProfile>())); }
public OrderService(IDB db) { _db = db; _mapper = new Mapper( new MapperConfiguration( cfg => cfg .AddProfile <OrderProfile>())); }
public BurgerRepository(IDB db, IServiceable <Ingredient> ingredientService) { _db = db; _ingredientService = ingredientService; _burgers = new List <Burger>(); GetBurgersFromDB(); AddIngredients(); }
/// <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); }
public IngredientService(IDB db) { _db = db; _mapper = new Mapper( new MapperConfiguration( cfg => cfg .AddProfile <IngredientProfile>())); }
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); }
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; }
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; }
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); }
private static long _total(string model) { IDB db = Get(model); if (db != null) { return(db.Count()); } return(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)); }
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(); } }
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(); } }
public LMAcquireParams(IDB x) { db = x; }
public AcquireParams() { db = new DB2(true); }
public AlphaBeta(IDB db = null) : base("alpha_beta_rec", db) { }
public override void Save (IDB db) { throw new Exception ("Can't save a View"); }
public AcquireParams(IDB db) { this.db = db; }
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); }
public LMMultiplicityParams(IDB db = null) : base("LMMultiplicity", db) { }
public ShiftRegisterParams2(IDB db = null) : base("sr_parms_rec", db) { }
public ShiftRegisterParams(bool newid = false) { db = new DB(false); Id = newid; }
public SRParamsExtension(IDB db = null) : base("sr_parms_ext", db) { }
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(); } }
public long CreateCfg(long id, ElementList sParams, IDB db) { return CreateTbl(id, "LMHWParams", sParams, db); }
public Detectors(IDB existing) { db = existing; }
public LMNetCommParams(IDB _db) { db = _db; }
public Detectors() { db = new DB(false); }
public LMNetCommParams() { db = new DB(false); }
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(); } }
public ShiftRegisterParams(IDB _db, bool newid = false) { db = _db; Id = newid; }
public bool UpdateCfg(long id, ElementList sParams, IDB db) { return UpdateTbl(id, "LMHWParams", sParams, db); }
public bool UpdateNetComm(long id, ElementList sParams, IDB db) { return UpdateTbl(id, "LMNetComm", sParams, db); }
public long CreateNetComm(long id, ElementList sParams, IDB db) { return CreateTbl(id, "LMNetComm", sParams, db); }
public override void Delete (IDB db) { throw new Exception ("Can't delete a View"); }
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); } }
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); }