private void btnDeleteOrderTruck_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(selectedOrderTruck)) { if (cbbCustomer.SelectedIndex < 0 || cbbMaterialType.SelectedIndex < 0 || String.IsNullOrEmpty(txtSubTotal.Text)) { MessageBox.Show("Please select the ordertruck to delete.", "Message"); } else { try { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; OrderTruck deleteOrderTruck = new OrderTruck(); deleteOrderTruck.deleteOrderTruck(mongoDBConnection.getMongoData(), selectedOrderTruck); MessageBox.Show("Order truck is deleted successfully.", "Message"); this.clearOrderTruckTab(); this.displayDataTableOrderTruck(dataGridViewOrderTruck); this.loadValueCustomeFilterCombobox(cbbSearchCustomer); this.loadValueFilterMaterialTypeCombobox(cbbSearchMaterialType); this.resetFilterValue(); } catch (Exception) { MessageBox.Show("Failed to delete the customer. Please try again.", "Message"); } } } else { MessageBox.Show("Please select the customer to delete.", "Message"); } }
private void btnDeleteUser_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtUserName.Text.Trim())) { DialogResult dr = MessageBox.Show("Do you want to update this user?", "Confirmed Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; User deleteUser = new User(); try { deleteUser.deleteByUsername(mongoDBConnection.getMongoData(), txtUserName.Text.Trim()); MessageBox.Show("The user is deleted successfully.", "Message"); txtUserName.Clear(); txtPassword.Clear(); if (ckcActive.Checked) { ckcActive.Checked = false; } txtUserName.Enabled = true; this.displayDataTableUser(dataGridViewUser); } catch (Exception) { MessageBox.Show("Failed to delete this user. Please try again.", "Message"); } } } else { MessageBox.Show("Please select the user to delete.", "Message"); } }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getall")] HttpRequestMessage req, TraceWriter log) { var driverData = MongoDBConnection.GetCollection <dynamic>("DriverCollectionName").Find(new BsonDocument()).ToList(); // Fetching the name from the path parameter in the request URL test return(req.CreateResponse(HttpStatusCode.OK, driverData, JsonMediaTypeFormatter.DefaultMediaType)); }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "promodata/{series}")] HttpRequestMessage req, string series, TraceWriter log) { IDatabase cache = RedisConnection.Connection.GetDatabase(); string redisKey = System.Environment.GetEnvironmentVariable("RedisKeyModelThree"); List <PromoData> promos = new List <PromoData>(); var length = cache.ListLength(redisKey); if (length > 0)//in redis { foreach (string item in cache.ListRange(redisKey, 0, (length - 1))) { promos.Add(JsonConvert.DeserializeObject <PromoData>(item)); } } else//get from mongodb and insert into redis { var promoCollection = MongoDBConnection.GetCollection <PromoData>("PromotionCollectionName"); promos = promoCollection.AsQueryable().OrderByDescending(p => p.CreatedTime).Take(5).ToList(); log.Info(promos.Count().ToString()); foreach (var promo in promos) { cache.ListLeftPush(redisKey, JsonConvert.SerializeObject(promo)); } cache.ListTrim(redisKey, 0, 4); } return(req.CreateResponse(HttpStatusCode.OK, promos, JsonMediaTypeFormatter.DefaultMediaType)); }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "id/{name}")] HttpRequestMessage req, string name, TraceWriter log) { string query = "{VehicleId:{$eq:\"" + name + "\"}}"; var data = MongoDBConnection.GetCollection <dynamic>("DriverCollectionName").Find(query).ToList(); // Fetching the name from the path parameter in the request URL test return(req.CreateResponse(HttpStatusCode.OK, data, JsonMediaTypeFormatter.DefaultMediaType)); }
private void btnUpdateCustomer_Click(object sender, EventArgs e) { Customer currentCustomer = new Customer(); String updateName = txtName.Text.Trim(); String updatePhoneNumber = txtPhoneNumber.Text.Trim(); String updateAddress = txtAddress.Text.Trim(); bool updateIsActive = ckcActiveCustomer.Checked; if (!String.IsNullOrEmpty(selectedCustomer)) { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; currentCustomer = currentCustomer.findCustomerByID(mongoDBConnection.getMongoData(), selectedCustomer); Customer updateCustomer = new Customer(); if (String.IsNullOrEmpty(txtName.Text) && String.IsNullOrEmpty(txtPhoneNumber.Text)) { MessageBox.Show("Please enter name and phone number.", "Message"); } else if (String.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("Please enter name field.", "Message"); } else if (String.IsNullOrEmpty(txtPhoneNumber.Text)) { MessageBox.Show("Please enter phone number field.", "Message"); } else { updateCustomer.name = updateName; updateCustomer.phoneNumber = updatePhoneNumber; updateCustomer.address = updateAddress; updateCustomer.isActive = updateIsActive; updateCustomer.modifyDate = DateTime.Now.ToUniversalTime(); currentCustomer.updateCustomer(mongoDBConnection.getMongoData(), currentCustomer, updateCustomer); MessageBox.Show("The customer is updated successfully.", "Message"); selectedCustomer = String.Empty; txtName.Clear(); txtPhoneNumber.Clear(); txtAddress.Clear(); if (ckcActiveCustomer.Checked) { ckcActiveCustomer.Checked = false; } this.displayDataTableCustomer(dataGridViewCustomer); this.loadValueCustomerCombobox(cbbCustomer); OrderTruck orderTruck = new OrderTruck(); updateCustomer = updateCustomer.findCustomerByID(mongoDBConnection.getMongoData(), currentCustomer._id.ToString()); // Update all order truck with update customer's info. orderTruck.updateOrderTruckByCustomer(mongoDBConnection.getMongoData(), updateCustomer); this.displayDataTableOrderTruck(dataGridViewOrderTruck); } } else { MessageBox.Show("Please select the customer to delete.", "Message"); } }
public void displayDataTableOrderTruck(DataGridView dataGridView) { OrderTruck orderTruckData = new OrderTruck(); MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; List <OrderTruck> listOrderTrucks = orderTruckData.getAllOrderTrucks(mongoDBConnection.getMongoData()); listOrderTrucksFilter = listOrderTrucks; this.viewDataTableOrdertruck(dataGridViewOrderTruck, listOrderTrucks); }
public PlaylistsRepository(MongoDBConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } _collection = connection.GetCollection <Playlist>(CollectionName); }
private void btnAddOrderTruck_Click(object sender, EventArgs e) { String customerName = ""; String materialType = ""; String note = txtNote.Text.Trim(); if (cbbCustomer.SelectedIndex < 0) { MessageBox.Show("Please select the customer's name.", "Message"); } else if (cbbMaterialType.SelectedIndex < 0) { MessageBox.Show("Please select the material type.", "Message"); } else if (String.IsNullOrEmpty(txtSubTotal.Text.Trim())) { MessageBox.Show("Please input the subtotal.", "Message"); } else if (dateTPCompletedDay.CustomFormat == " ") { MessageBox.Show("Please select the completed day.", "Message"); } else { customerName = cbbCustomer.SelectedItem.ToString().Trim(); materialType = cbbMaterialType.SelectedItem.ToString().Trim(); MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; Customer selectedCustomer = new Customer(); selectedCustomer = selectedCustomer.findCustomerByName(customerName, mongoDBConnection.getMongoData()); DateTime completedDay = dateTPCompletedDay.Value.ToUniversalTime(); OrderTruck newOrderTruck = new OrderTruck(); newOrderTruck.customer = selectedCustomer; newOrderTruck.materialType = materialType; newOrderTruck.subtotal = int.Parse(txtSubTotal.Text.Trim()); newOrderTruck.note = txtNote.Text.Trim(); newOrderTruck.completedDate = completedDay; newOrderTruck.createDate = DateTime.Now.ToUniversalTime(); newOrderTruck.modifyDate = DateTime.Now.ToUniversalTime(); newOrderTruck.isPaid = ckcIsPaid.Checked; this.clearOrderTruckTab(); try { newOrderTruck.addOrderTruck(mongoDBConnection.getMongoData(), newOrderTruck); MessageBox.Show("New order truck is add successfully.", "Message"); this.clearOrderTruckTab(); this.displayDataTableOrderTruck(dataGridViewOrderTruck); this.loadValueCustomeFilterCombobox(cbbSearchCustomer); this.loadValueFilterMaterialTypeCombobox(cbbSearchMaterialType); this.resetFilterValue(); } catch (Exception) { MessageBox.Show("Failed to add new order truck. Please try again.", "Message"); } } }
public async static Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "content/{id}")] HttpRequestMessage req, string id, TraceWriter log) { //add content into MongoDB dynamic data = await req.Content.ReadAsStringAsync(); var circleData = JsonConvert.DeserializeObject <CircleData>(data as string); MongoDBConnection.GetCollection <CircleData>("CircleCollectionName").InsertOne(circleData); return(req.CreateResponse(HttpStatusCode.OK, "Inserted")); }
public void loadValueCustomerCombobox(ComboBox customerCombobox) { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; Customer customer = new Customer(); List <Customer> listCustomers = customer.getAllActiveCustomers(mongoDBConnection.getMongoData()); cbbCustomer.Items.Clear(); cbbCustomer.ResetText(); foreach (Customer customer1 in listCustomers) { cbbCustomer.Items.Add(customer1.name); } }
public void displayDataTableUser(DataGridView dataGridView) { User userData = new User(); MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; List <User> listUsers = userData.getListAllUsers(mongoDBConnection.getMongoData()); dataGridView.Rows.Clear(); dataGridView.Refresh(); for (int i = 0; i < listUsers.Count; i++) { dataGridView.Rows.Add(new object[] { i + 1, listUsers[i].userName, listUsers[i].passWord, listUsers[i].createDate.ToLocalTime(), listUsers[i].active }); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var mongoDBConnection = new MongoDBConnection() { MongoClientSettings = GetMongoDBSettings(Configuration), DatabaseName = Configuration["AppSettings:MongoDBName"] }; services.AddSingleton <IMongoDBConnection>(mongoDBConnection); services.AddSingleton <IActionRepository, ActionRepository>(); services.AddMvc(); }
private void btnAddCustomer_Click(object sender, EventArgs e) { String name = txtName.Text.Trim(); String phoneNumber = txtPhoneNumber.Text.Trim(); String address = txtAddress.Text.Trim(); bool isActive = ckcActiveCustomer.Checked; Customer newCustomer = new Customer(); newCustomer.name = name; newCustomer.phoneNumber = phoneNumber; newCustomer.address = address; newCustomer.isActive = ckcActiveCustomer.Checked; newCustomer.createDate = DateTime.Now.ToUniversalTime(); newCustomer.modifyDate = DateTime.Now.ToUniversalTime(); if (String.IsNullOrEmpty(name) && String.IsNullOrEmpty(phoneNumber)) { MessageBox.Show("Please enter name and phone number.", "Message"); } else if (String.IsNullOrEmpty(name)) { MessageBox.Show("Please enter name field.", "Message"); } else if (String.IsNullOrEmpty(phoneNumber)) { MessageBox.Show("Please enter phone number field.", "Message"); } else { try { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; newCustomer.addCustomer(mongoDBConnection.getMongoData(), newCustomer); MessageBox.Show("New Customer is added successfully.", "Message"); txtName.Clear(); txtPhoneNumber.Clear(); txtAddress.Clear(); if (ckcActiveCustomer.Checked) { ckcActiveCustomer.Checked = false; } this.displayDataTableCustomer(dataGridViewCustomer); this.loadValueCustomerCombobox(cbbCustomer); } catch (Exception) { MessageBox.Show("Failed to add new customer. Please try again.", "Message"); } } }
private void btnUpdateUser_Click(object sender, EventArgs e) { String username = txtUserName.Text.Trim(); String password = txtPassword.Text.Trim(); if (String.IsNullOrEmpty(username) && String.IsNullOrEmpty(password)) { MessageBox.Show("Please enter your username and passowrd.", "Message"); } else if (String.IsNullOrEmpty(username)) { MessageBox.Show("Please enter your username.", "Message"); } else if (String.IsNullOrEmpty(password)) { MessageBox.Show("Please enter your passowrd.", "Message"); } else { DialogResult dr = MessageBox.Show("Do you want to update this user?", "Confirmed Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; User currentUser = new User(); try { currentUser = currentUser.findUserByName(username, mongoDBConnection.getMongoData()); User newUser = new User(); newUser.passWord = password; newUser.active = ckcActive.Checked; currentUser.updateUser(mongoDBConnection.getMongoData(), currentUser, newUser); MessageBox.Show("The user is updated successfully.", "Message"); txtUserName.Clear(); txtPassword.Clear(); if (ckcActive.Checked) { ckcActive.Checked = false; } txtUserName.Enabled = true; this.displayDataTableUser(dataGridViewUser); } catch (Exception) { MessageBox.Show("Failed to update this user. Please try again.", "Message"); } } } }
public void displayDataTableCustomer(DataGridView dataGridView) { Customer customerData = new Customer(); MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; List <Customer> listCustomers = customerData.getAllCustomers(mongoDBConnection.getMongoData()); dataGridViewCustomer.Rows.Clear(); dataGridViewCustomer.Refresh(); for (int i = 0; i < listCustomers.Count; i++) { dataGridViewCustomer.Rows.Add(new object[] { i + 1, listCustomers[i].name, listCustomers[i].phoneNumber, listCustomers[i].address, listCustomers[i].createDate.ToLocalTime().ToString("dd/MM/yyyy"), listCustomers[i].modifyDate.ToLocalTime().ToString("dd/MM/yyyy"), listCustomers[i].isActive, listCustomers[i]._id }); } for (int i = 0; i < dataGridView.ColumnCount; i++) { dataGridView.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } }
static void Main(string[] args) { var con = new MongoDBConnection("Server=127.0.0.1;Port=27017;Database=cdactraining;"); var cmd = new MongoDBCommand("SELECT * FROM employees", con); try { con.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader["empName"]); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void btnAddUser_Click(object sender, EventArgs e) { String username = txtUserName.Text.Trim(); String password = txtPassword.Text.Trim(); if (String.IsNullOrEmpty(username) && String.IsNullOrEmpty(password)) { MessageBox.Show("Please enter your username and passowrd.", "Message"); } else if (String.IsNullOrEmpty(username)) { MessageBox.Show("Please enter your username.", "Message"); } else if (String.IsNullOrEmpty(password)) { MessageBox.Show("Please enter your passowrd.", "Message"); } else { User newUser = new User(); newUser.userName = username; newUser.passWord = newUser.getMD5(password); newUser.createDate = DateTime.Now.ToUniversalTime(); newUser.active = ckcActive.Checked; try { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; newUser.addUser(mongoDBConnection.getMongoData(), newUser); MessageBox.Show("New user is added successfully.", "Message"); txtUserName.Clear(); txtPassword.Clear(); if (ckcActive.Checked) { ckcActive.Checked = false; } this.displayDataTableUser(dataGridViewUser); } catch (Exception) { MessageBox.Show("Failed to add new user. Please try again.", "Message"); } } }
private void btnDeleteCustomer_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(selectedCustomer)) { if (String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtPhoneNumber.Text) || String.IsNullOrEmpty(txtAddress.Text)) { MessageBox.Show("Please select the customer to delete.", "Message"); } else { try { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; Customer deleteCustomer = new Customer(); deleteCustomer.deleteCustomer(mongoDBConnection.getMongoData(), selectedCustomer); MessageBox.Show("Customer is deleted successfully . Please try again.", "Message"); selectedCustomer = String.Empty; txtName.Clear(); txtPhoneNumber.Clear(); txtAddress.Clear(); if (ckcActiveCustomer.Checked) { ckcActiveCustomer.Checked = false; } this.displayDataTableCustomer(dataGridViewCustomer); this.loadValueCustomerCombobox(cbbCustomer); } catch (Exception) { MessageBox.Show("Failed to delete the customer. Please try again.", "Message"); } } } else { MessageBox.Show("Please select the customer to delete.", "Message"); } }
/// <summary> /// To get the mongo db connection /// </summary> /// <param name="dataBaseName">The database name.</param> /// <returns>A Mongo Database</returns> private MongoDatabase GetMyDiaryMongoDbConnection(string dataBaseName) { return(MongoDBConnection.Get("mongodb://localhost", dataBaseName)); }
public static WriteConcernResult Delete(MongoDBConnection db, string id) { return db.Comments.Remove(Query.EQ("_id", id)); }
public static IEnumerable<Comment> Get(MongoDBConnection db, string uid) { return db.Comments.FindAll().Where(i => i.CreatedByUID == uid); }
private void Login_Click(object sender, EventArgs e) { String username = txtUserName.Text.Trim(); String password = txtPassword.Text.Trim(); if (String.IsNullOrEmpty(username) && String.IsNullOrEmpty(password)) { MessageBox.Show("Please enter your username and passowrd.", "Message"); } else if (String.IsNullOrEmpty(username)) { MessageBox.Show("Please enter your username.", "Message"); } else if (String.IsNullOrEmpty(password)) { MessageBox.Show("Please enter your passowrd.", "Message"); } else { MongoDBConnection mongoDBConnection = null; try { mongoDBConnection = MongoDBConnection.getMongoConnection; Console.WriteLine(mongoDBConnection); IMongoDatabase mongoDatabase = mongoDBConnection.getMongoData(); User loginUser = new User(); //{ // userName = "******", // passWord = "******", // createDate = DateTime.Now.ToUniversalTime() //}; loginUser = loginUser.findUserByName(username, mongoDatabase); if (null != loginUser) { if (loginUser.passWord.Equals(loginUser.getMD5(password))) { if (!loginUser.active) { MessageBox.Show("Your username is inactive. Please try again.", "Message"); txtUserName.Clear(); txtPassword.Clear(); } else { Console.WriteLine(loginUser.createDate.ToLocalTime().ToString()); this.Hide(); var form = new Form2(); form.Show(); } } else { MessageBox.Show("Your password is incorrect. Please try again.", "Message"); txtPassword.Clear(); } } else { MessageBox.Show("Your username is incorrect. Please try again.", "Message"); txtUserName.Clear(); txtPassword.Clear(); }; } catch (TimeoutException e1) { MessageBox.Show("Please check your connection again.", "Message"); Console.WriteLine(e1.ToString()); } } }
public MongoDBTransaction(IClientSessionHandle clientSessionHandle, MongoDBConnection mongoDBConnection) { _clientSessionHandle = clientSessionHandle; _mongoDBConnection = mongoDBConnection; }
//public static WriteConcernResult Create(MongoDBConnection db, SetterComment SetterComment) //{ // // TODO //} public static Comment IsUniqueComment(MongoDBConnection db, SetterComment SetterComment) { if (db.Comments.Count() > 0) { return db.Comments.FindOne(Query<Comment>.Where(i => i.PostId == SetterComment.PostId && (i.PostId == SetterComment.PostId && i.CreatedByUID == SetterComment.CreatedByUID))); } return null; }
private void UpdateAccessTime(AssetBase asset) { using (MongoDBConnection dbcon = new MongoDBConnection(m_connectionString)) { dbcon.Open(); using (MongoDBCommand cmd = new MongoDBCommand("update assets set access_time=?access_time where id=?id", dbcon)) { try { using (cmd) { // create unix epoch time int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); cmd.Parameters.AddWithValue("?id", asset.ID); cmd.Parameters.AddWithValue("?access_time", now); cmd.ExecuteNonQuery(); } } catch (Exception e) { m_log.Error( string.Format( "[ASSETS DB]: Failure updating access_time for asset {0} with name {1}. Exception ", asset.FullID, asset.Name), e); } } } }
/// <summary> /// Check if the assets exist in the database. /// </summary> /// <param name="uuidss">The assets' IDs</param> /// <returns>For each asset: true if it exists, false otherwise</returns> public override bool[] AssetsExist(UUID[] uuids) { if (uuids.Length == 0) return new bool[0]; HashSet<UUID> exist = new HashSet<UUID>(); string ids = "'" + string.Join("','", uuids) + "'"; string sql = string.Format("SELECT id FROM assets WHERE id IN ({0})", ids); using (MongoDBConnection dbcon = new MongoDBConnection(m_connectionString)) { dbcon.Open(); using (MongoDBCommand cmd = new MongoDBCommand(sql, dbcon)) { using (MongoDBDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { UUID id = DBGuid.FromDB(dbReader["id"]); exist.Add(id); } } } } bool[] results = new bool[uuids.Length]; for (int i = 0; i < uuids.Length; i++) results[i] = exist.Contains(uuids[i]); return results; }
/// <summary> /// Returns a list of AssetMetadata objects. The list is a subset of /// the entire data set offset by <paramref name="start" /> containing /// <paramref name="count" /> elements. /// </summary> /// <param name="start">The number of results to discard from the total data set.</param> /// <param name="count">The number of rows the returned list should contain.</param> /// <returns>A list of AssetMetadata objects.</returns> public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { List<AssetMetadata> retList = new List<AssetMetadata>(count); using (MongoDBConnection dbcon = new MongoDBConnection(m_connectionString)) { dbcon.Open(); using (MongoDBCommand cmd = new MongoDBCommand( "SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count", dbcon)) { cmd.Parameters.AddWithValue("?start", start); cmd.Parameters.AddWithValue("?count", count); try { using (MongoDBDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { AssetMetadata metadata = new AssetMetadata(); metadata.Name = (string)dbReader["name"]; metadata.Description = (string)dbReader["description"]; metadata.Type = (sbyte)dbReader["assetType"]; metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct. metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); metadata.FullID = DBGuid.FromDB(dbReader["id"]); metadata.CreatorID = dbReader["CreatorID"].ToString(); // Current SHA1s are not stored/computed. metadata.SHA1 = new byte[] { }; retList.Add(metadata); } } } catch (Exception e) { m_log.Error( string.Format( "[ASSETS DB]: MongoDB failure fetching asset set from {0}, count {1}. Exception ", start, count), e); } } } return retList; }
public override bool Delete(string id) { using (MongoDBConnection dbcon = new MongoDBConnection(m_connectionString)) { dbcon.Open(); using (MongoDBCommand cmd = new MongoDBCommand("delete from assets where id=?id", dbcon)) { cmd.Parameters.AddWithValue("?id", id); cmd.ExecuteNonQuery(); } } return true; }
private void btnUpdateOrderTruck_Click(object sender, EventArgs e) { String customerName = ""; String materialType = ""; String note = txtNote.Text.Trim(); if (cbbCustomer.SelectedIndex < 0) { MessageBox.Show("Please select the customer's name to update order truck.", "Message"); } else if (cbbMaterialType.SelectedIndex < 0) { MessageBox.Show("Please select the material type to update order truck.", "Message"); } else if (String.IsNullOrEmpty(txtSubTotal.Text.Trim())) { MessageBox.Show("Please input the subtotal to update order truck.", "Message"); } //else if (dateTPCompletedDay.CustomFormat == " ") //{ // MessageBox.Show("Please select the completed day to update order truck.", "Message"); //} else { if (!String.IsNullOrEmpty(selectedOrderTruck)) { try { MongoDBConnection mongoDBConnection = MongoDBConnection.getMongoConnection; OrderTruck currentOrderTruck = new OrderTruck(); OrderTruck updatedOrderTruck = new OrderTruck(); Customer updatedCustomer = new Customer(); currentOrderTruck = currentOrderTruck.getOrderTruckByID(mongoDBConnection.getMongoData(), selectedOrderTruck); updatedOrderTruck.customer = updatedCustomer.findCustomerByName(cbbCustomer.SelectedItem.ToString(), mongoDBConnection.getMongoData()); updatedOrderTruck.materialType = cbbMaterialType.SelectedItem.ToString().Trim(); updatedOrderTruck.note = txtNote.Text.Trim(); updatedOrderTruck.subtotal = int.Parse(txtSubTotal.Text.Trim()); if (dateTPCompletedDay.CustomFormat == " ") { updatedOrderTruck.completedDate = currentOrderTruck.completedDate; } else { updatedOrderTruck.completedDate = dateTPCompletedDay.Value.ToUniversalTime(); } updatedOrderTruck.modifyDate = DateTime.Now.ToUniversalTime(); updatedOrderTruck.isPaid = ckcIsPaid.Checked; updatedOrderTruck.updateOrderTruck(mongoDBConnection.getMongoData(), currentOrderTruck, updatedOrderTruck); MessageBox.Show("The order truck is updated successfully.", "Message"); selectedOrderTruck = String.Empty; this.clearOrderTruckTab(); this.displayDataTableOrderTruck(dataGridViewOrderTruck); this.loadValueCustomeFilterCombobox(cbbSearchCustomer); this.loadValueFilterMaterialTypeCombobox(cbbSearchMaterialType); this.resetFilterValue(); } catch (Exception) { MessageBox.Show("Failed to update the selected order truck. Please try again.", "Message"); } } else { MessageBox.Show("Please select the order truck to update.", "Message"); } } }
public MongoDBUnitofWork(IConnection _conn) { _MongoDBConn = (MongoDBConnection)_conn; }