public Record Get(string recordType, Guid id, List <string> columns) { // because apparently comma seperation isn't enough to make a list if (columns.Count == 1) { columns = columns[0].Split(",").ToList(); } IDataSource data = new Postgres(connectionString); DataService service = new DataService(); service.data = data; if (columns.Count == 0) { RetrieveRecordTypeCommand retrieveCommand = new RetrieveRecordTypeCommand() { RecordType = recordType, }; RetrieveRecordTypeResult typeResult = (RetrieveRecordTypeResult)service.Execute(retrieveCommand); columns = typeResult.Type.FieldNames; } RetrieveRecordCommand command = new RetrieveRecordCommand() { Type = recordType, Fields = columns, Id = id, AllFields = false, }; RetrieveRecordResult result = (RetrieveRecordResult)service.Execute(command); return(result.Result); }
public ParseDemocracy() { var dbCon = "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password="******"wss://kusama-rpc.polkadot.io/"; _app = PolkaApi.GetAppication(); _sch = new MetadataSchema(); string nodeUrl = substrateCon; _app.Connect(nodeUrl); // Connect to db and check metadata version _postgres = new Postgres(dbCon); _indexer = new Indexer(_app, _postgres); // Create or update current schema var metadata = _app.GetMetadata(null); _sch.ParseMetadata(metadata); var si = _app.GetSystemInfo(); _sch.DatabaseSchema.Title = "Test_ParseBalances"; _sch.CommitToDb(_postgres, si); // Check current schema _indexer.CheckSystemInfo(); }
/** * Constructor for PostgresResult * * @param stmt the corresponding statement * @param rs the corresponding result set * @param conn the corresponding connection */ public PostgresResult(Postgres conn, Statement stmt, ResultSet rs) { super(rs); _conn = conn; _stmt = stmt; }
public List <Record> GetAll(string recordType, List <string> columns) { IDataSource data = new Postgres(connectionString); DataService service = new DataService(); service.data = data; if (columns.Count == 0) { RetrieveRecordTypeCommand retrieveCommand = new RetrieveRecordTypeCommand() { RecordType = recordType, }; RetrieveRecordTypeResult typeResult = (RetrieveRecordTypeResult)service.Execute(retrieveCommand); columns = typeResult.Type.FieldNames; } RetrieveAllCommand command = new RetrieveAllCommand() { RecordType = recordType, Columns = columns }; RetrieveAllResult result = (RetrieveAllResult)service.Execute(command); return(result.Result); }
public int Add(Postgres connection, User user) { var queryConstructor = new QueryConstructor <User>(); var sql = queryConstructor.BuildeInsertQuery(user, "public", "user", false); return(connection.ExecuteReturnIdIntTransaction(sql, "id")); }
protected override ValidationResult IsValid( object value, ValidationContext validationContext) { Postgres db = (Postgres)validationContext.GetService(typeof(Postgres)); NpgsqlConnection connection = db.Database.GetDbConnection() as NpgsqlConnection; if (value == null) { return(ValidationResult.Success); } if (connection.State != System.Data.ConnectionState.Open) { connection.Open(); } using (NpgsqlCommand command = connection.CreateCommand()) { command.CommandText = $"SELECT id FROM {Table} WHERE {Column}=@value LIMIT 1"; command.Parameters.AddWithValue("@value", value); command.Prepare(); object data = command.ExecuteScalar(); if (data != null) { return(new ValidationResult(GetErrorMessage())); } } return(ValidationResult.Success); }
public static List <LonLatWykr> GetCamerasList() { using (var pg = new Postgres()) { var data = pg.Query(@"select id, lat, lon, is_wykryty from ( select c.id, c.geolat as lat , c.geolon as lon , case when wykrytocolumn1 = 1 and log_date > now() - interval '1' minute then 1 else 0 end as is_wykryty , rank() over(partition by c.id order by cl.log_date desc) as rn from cameras c left outer join cameralog cl on cl.camera_fk = c.id and cl.field_fk = c.currentfield_fk order by c.id ) X where rn = 1").Fetch(); var ret = new List <LonLatWykr>(); foreach (DataRow row in data.Rows) { var item = new LonLatWykr { lon = Convert.ToString(row["lon"]), lat = Convert.ToString(row["lat"]), is_wykryty = Convert.ToInt64(row["is_wykryty"]), }; ret.Add(item); } return(ret); } }
public BundleSearch(Postgres postgres, OracleDB oracle, LookUp lookup) { this.postgres = postgres; this.oracle = oracle; this.lookup = lookup; InitializeComponent(); }
public ContentController(Postgres postgres, Mongo mongo, Redis redis, Elastic elastic, Wrappers.Neo4j neo4j) { this.postgres = postgres; this.mongo = mongo; this.redis = redis; this.elastic = elastic; this.neo4j = neo4j; }
public static DataTable loadAllMembers() { DataTable a = new DataTable(); string sql = "select id as 会员排名, username as 会员, mobile as 电话号码 from members"; a = Postgres.ExecuteSQL(sql); return(a); }
static void Main(string[] args) { MetadataSchema sch = new MetadataSchema(); using (IApplication app = PolkaApi.GetAppication()) { bool reconnect = true; while (reconnect) { try { string nodeUrl = ConfigurationManager.AppSettings["Substrate"]; var metadataBlockHash = ConfigurationManager.AppSettings["MetadataBlockHash"]; app.Connect(nodeUrl, metadataBlockHash); // Connect to db and check metadata version var postgres = new Postgres(ConfigurationManager.ConnectionStrings["Postgres"].ConnectionString); var indexer = new Indexer(app, postgres); // Create or update current schema var startBlock = 0; int.TryParse(ConfigurationManager.AppSettings["StartBlockNum"], out startBlock); var metadata = app.GetMetadata(null); //var metadata = app.GetMetadata(null); sch.ParseMetadata(metadata); var si = app.GetSystemInfo(); sch.CommitToDb(postgres, si); // Check current schema indexer.CheckSystemInfo(); // Parse blocks indexer.Scan(startBlock); } catch (System.ApplicationException appex) { Console.WriteLine("ApplicationException caught: " + appex.Message); reconnect = appex.Message.Contains("Not connected"); } catch (Exception e) { Console.WriteLine("Exception caught: " + e.ToString()); if (e.Message.Contains("The operation has timed out")) { reconnect = true; } else { reconnect = false; } } finally { app.Disconnect(); } } } Console.ReadLine(); }
private static void UserCheck() { string sqlUser = "******"; string sqlInsertUser = "******"; if (Convert.ToInt32(Postgres.ExecuteScaler(sqlUser)) < 1) { Postgres.ExecuteNonQuery(sqlInsertUser); } }
public LoosePieceSearch(Postgres postgres, OracleDB oracle, LookUp lookup) { this.postgres = postgres; this.oracle = oracle; this.lookup = lookup; InitializeComponent(); toolStripComboBoxWarehouse.SelectedIndex = Properties.Settings.Default.DEFAULT_WAREHOUSE_INDEX; toolStripComboBoxContainerType.SelectedIndex = Properties.Settings.Default.DEFAULT_CONTAINER_TYPE_INDEX; }
public MainForm(Postgres postgres) { this.postgres = postgres; timeClock = new TimeClock(postgres); InitializeComponent(); sessionKeyTextBox.MaxLength = 4; getShippers(); }
public void Delete(string recordType, Guid id) { IDataSource data = new Postgres(connectionString); DataService service = new DataService(); service.data = data; DeleteRecordCommand command = new DeleteRecordCommand() { Type = recordType, Id = id, }; DeleteRecordResult result = (DeleteRecordResult)service.Execute(command); }
public void Update(string recordType, Guid id, [FromBody] Record record) { IDataSource data = new Postgres(connectionString); DataService service = new DataService(); service.data = data; record.Id = id; record.Type = recordType; UpdateRecordCommand command = new UpdateRecordCommand() { Target = record }; UpdateRecordResult result = (UpdateRecordResult)service.Execute(command); }
static void Main() { postgres = new Postgres(LoadPostgresConfig()); TestDatabaseConnections(); postgres.OpenConnection(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(postgres)); postgres.CloseConnection(); }
private void btnSearchMem_Click(object sender, EventArgs e) { string m = textBox1.Text.Trim(); if (string.IsNullOrEmpty(m)) { MessageBox.Show("请输入会员名或者电话!"); return; } else { DataTable dtm = Postgres.GetMemberBySearchText(m); dataGridViewMember.DataSource = dtm; } }
public Guid Post(string recordType, [FromBody] Record record) { IDataSource data = new Postgres(connectionString); DataService service = new DataService(); service.data = data; record.Type = recordType; CreateRecordCommand command = new CreateRecordCommand() { Target = record, }; CreateRecordResult result = (CreateRecordResult)service.Execute(command); return(result.RecordId); }
static void Main(string[] args) { var db = new Postgres(); var ret = db.Query("SELECT * FROM cameras WHERE id=:id") .Bind("id", 1) .Fetch(); var fac = new camerasFactory(db); fac.Add(1, "Nowa kamera", "12.34", "34.56"); fac.Edit(20, 1, "Zmiana!", "23.322", "123.45"); fac.Delete(25); new cameralogFactory(db).Add(1, 1, "www.new.pl", "12.3", "123.32", "Nazwa!"); }
private void btnOK_Click(object sender, EventArgs e) { string user = txtBoxUsername.Text.Trim(); string oldPwd = txtBoxPassword.Text.Trim(); string newPwd = txtBoxNewPwd.Text.Trim(); string newPwd2 = txtBoxNewPwd2.Text.Trim(); string sqlSelectUser = "******" + user + "'"; string sqlUpdateUser = "******" + "where username='******'"; DataTable dt = new DataTable(); dt = Postgres.ExecuteSQL(sqlSelectUser); if (dt.Rows.Count > 0) { //user exist if (dt.Rows[0][1].ToString() != oldPwd) { MessageBox.Show("原密码输入有误,请重新输入!"); return; } else { if (newPwd == newPwd2 && newPwd != oldPwd) { Postgres.ExecuteNonQuery(sqlUpdateUser); this.Close(); } else if (newPwd == oldPwd) { MessageBox.Show("新密码和原密码不能相同,请重新输入!"); return; } else { MessageBox.Show("新密码两次输入不相同,请重新输入!"); return; } } } else { MessageBox.Show("用户不存在!"); return; } this.Close(); }
/// <summary> /// Create a new cannibalization control /// </summary> /// <param name="postgres">Postgres object</param> /// <param name="oracle">Oracle object</param> public CannibalizationControl(Postgres postgres, OracleDB oracle, Search search, BarcodeParser barcodeParser) { this.postgres = postgres; this.oracle = oracle; this.barcodeParser = barcodeParser; this.search = search; InitializeComponent(); // Set control specific settings kitQueuePanel.AutoScroll = true; // Event Handlers this.cannibalizeSearchButton.Click += new EventHandler(this.cannibalizeSearchButton_Click); this.cannibalizeResetButton.Click += new EventHandler(this.cannibalizeResetButton_Click); this.kitQueueTable.CellContentClick += new DataGridViewCellEventHandler(this.kitQueueTable_CellContentClick); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins(ConfigurationManager.AppSettings["ClientUIHost"]) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); MetadataSchema sch = new MetadataSchema(); var MetadataBlockHash = ConfigurationManager.AppSettings["MetadataBlockHash"]; using (IApplication app = PolkaApi.GetAppication()) { app.Connect("wss://kusama-rpc.polkadot.io/", MetadataBlockHash); sch.ParseMetadata(app.GetMetadata(null)); app.Disconnect(); } var rt = File.ReadAllText("runtime.txt"); var dataReader = new Postgres(ConfigurationManager.ConnectionStrings["Postgres"].ConnectionString); services.AddSingleton(sch); services.AddSingleton(dataReader); services.AddSingleton <IRuntime>(new Runtime(rt)); services.AddSingleton <IWebApiDataAdapter>(new IndexedWebApi(dataReader, sch)); services.AddMvc() .AddJsonOptions(x => { x.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() }; }); }
private void 除此次消费记录ToolStripMenuItem_Click(object sender, EventArgs e) { int id = 0; DialogResult dr = MessageBox.Show("确认删除此次客户消费记录吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { int a = dataGridViewDetail.CurrentRow.Index; id = Convert.ToInt32(dataGridViewDetail.Rows[a].Cells[0].Value); string moible = dataGridViewDetail.Rows[a].Cells[2].Value.ToString(); string sqldelete = "delete from consumptiondetail where id='" + id + "'"; Postgres.ExecuteNonQuery(sqldelete); Postgres.RecalculateCustomer(Form1.mid); //dataGridViewDetail.DataSource = Postgres.GetConDetail(moible); reloadData(Form1.mid); } }
private void btnLogin_Click(object sender, EventArgs e) { string username = txtUsername.Text.Trim(); string password = txtPassword.Text.Trim(); string sqlUsers = "select count(*) from users where username='******'" + "and " + "password='******'"; int count = 0; count = Postgres.ExecuteScaler(sqlUsers); if (count != 0) { //User existed new Form1().ShowDialog(); this.Close(); } else { MessageBox.Show("用户名或者密码错误!"); } }
private void 除会员ToolStripMenuItem_Click(object sender, EventArgs e) { int id = 0; DialogResult dr = MessageBox.Show("确认删除此次客户消费记录吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { int a = dataGridViewMember.CurrentRow.Index; id = Convert.ToInt32(dataGridViewMember.Rows[a].Cells[0].Value); string sqldelete = "delete from members where id='" + id + "'"; Postgres.ExecuteNonQuery(sqldelete); Postgres.DeleteConSummaryByMid(id.ToString()); Postgres.DeleteConDetailByMid(id.ToString()); dataGridViewMember.DataSource = loadAllMembers(); } }
static void Main() { /* Load settings */ // Load Postgres and Oracle connections postgres = new Postgres(LoadPostgresConfig()); oracle = new OracleDB(LoadOracleConfig()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Check to see if we run connection checks if (Properties.Settings.Default.AUTOCONNECT) { // Load the splash screen and Show it as the connection is being tested SplashScreen splash = new SplashScreen(); splash.Show(); // Test Connection to Databases before fully running the application Thread t = new Thread(new ThreadStart(TestDatabaseConnections)); t.Start(); t.Join(); // connect to databases connect(); splash.Close(); } // Load main window form, initialize database connections mainWindow = new MainWindow( postgres, oracle ); // Run main application Application.Run(mainWindow); // Disconnect from databases disconnect(); }
/// <summary> /// Main constructor /// </summary> /// <param name="postgres">Postgres database object</param> /// <param name="oracle">OracleDB database object</param> public MainWindow(Postgres postgres, OracleDB oracle) { // Instantiate connections this.postgres = postgres; this.oracle = oracle; // Instantiate tools barcodeParser = new BarcodeParser(postgres, oracle); search = new Search(postgres, oracle, barcodeParser); CannibalizationControl cc = new CannibalizationControl(this.postgres, this.oracle, this.search, this.barcodeParser); cc.Dock = DockStyle.Fill; // Initialize Components onto the form InitializeComponent(); //Load controls tabCannibalize.Controls.Add(cc); }
public User GetUserById(string userID) { using (Postgres dbObj = new Postgres()) { string sql = "SELECT * FROM slotBooking.tbl_user where user_id = @UserId"; dbObj.AddParameter("@UserId", NpgsqlDbType.Varchar, userID); DataTable dataTable = dbObj.ExecuteReader(sql); User userData = new User(); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow row in dataTable.Rows) { userData.UserID = Convert.ToString(row["user_id"]); userData.FirstName = Convert.ToString(row["first_name"]); userData.LastName = Convert.ToString(row["last_name"]); userData.EmailID = Convert.ToString(row["email_id"]); userData.Password = Convert.ToString(row["password"]); } } return(userData); } }
public MainForm(Postgres postgres, OracleDB oracle) { this.postgres = postgres; this.oracle = oracle; lookup = new LookUp(postgres, oracle); InitializeComponent(); if (Properties.Settings.Default.LOAD_KITS_ON_START) { LoadEFCKitNumbers(); } LoosePieceSearch lps = new LoosePieceSearch(postgres, oracle, lookup); BundleSearch bs = new BundleSearch(postgres, oracle, lookup); lps.Dock = DockStyle.Fill; bs.Dock = DockStyle.Fill; mainForTabControl.TabPages[0].Controls.Add(bs); mainForTabControl.TabPages[1].Controls.Add(lps); }