private bool TryUpdateInventory(SPRemoteEventProperties properties) { bool successFlag = false; try { var arrived = Convert.ToBoolean(properties.ItemEventProperties.AfterProperties["Arrived"]); var addedToInventory = Convert.ToBoolean(properties.ItemEventProperties.AfterProperties["Added_x0020_to_x0020_Inventory"]); if (arrived && !addedToInventory) { using (SqlConnection conn = SQLAzureUtilities.GetActiveSqlConnection()) using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "UpdateInventory"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter tenant = cmd.Parameters.Add("@Tenant", SqlDbType.NVarChar); tenant.Value = properties.ItemEventProperties.WebUrl + "/"; SqlParameter product = cmd.Parameters.Add("@ItemName", SqlDbType.NVarChar, 50); product.Value = properties.ItemEventProperties.AfterProperties["Title"]; // not "Product" SqlParameter quantity = cmd.Parameters.Add("@Quantity", SqlDbType.SmallInt); quantity.Value = Convert.ToUInt16(properties.ItemEventProperties.AfterProperties["Quantity"]); cmd.ExecuteNonQuery(); } successFlag = true; } } catch (KeyNotFoundException) { successFlag = false; } return(successFlag); }
private void ShowAddinVersion() { using (SqlConnection conn = SQLAzureUtilities.GetActiveSqlConnection()) using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "GetTenantVersion"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter tenant = cmd.Parameters.Add("@Name", SqlDbType.NVarChar); tenant.Value = spContext.SPHostUrl.ToString(); using (SqlDataReader reader = cmd.ExecuteReader()) { string lblText = "Registered version: "; if (reader.HasRows) { while (reader.Read()) { lblText += (reader["Version"].ToString()); } } else { lblText = "There is no tenant named: " + spContext.SPHostUrl.ToString(); } lblAddinVersion.Text = lblText; } } }
private void ShowCorpEmployees() { using (SqlConnection conn = SQLAzureUtilities.GetActiveSqlConnection()) using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "ShowEmployees"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter tenant = cmd.Parameters.Add("@Tenant", SqlDbType.NVarChar); tenant.Value = spContext.SPHostUrl.ToString(); corpEmployeesGridView.DataSource = cmd.ExecuteReader(); corpEmployeesGridView.DataBind(); } }
private void AddLocalEmployeeToCorpDB(string employeeName) { using (SqlConnection conn = SQLAzureUtilities.GetActiveSqlConnection()) using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "AddEmployee"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter tenant = cmd.Parameters.Add("@Tenant", SqlDbType.NVarChar); tenant.Value = spContext.SPHostUrl.ToString(); SqlParameter name = cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 50); name.Value = employeeName; cmd.ExecuteNonQuery(); } }
private void DeleteTenant(string tenantName) { // Do not catch exceptions. Allow them to bubble up and trigger roll back // of un-installation (removal from 2nd level Recycle Bin). using (SqlConnection conn = SQLAzureUtilities.GetActiveSqlConnection()) using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "RemoveTenant"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter name = cmd.Parameters.Add("@Name", SqlDbType.NVarChar); name.Value = tenantName; cmd.ExecuteNonQuery(); }//dispose conn and cmd }
private void CreateOrder(String supplierName, String productName, UInt16 quantityOrdered) { using (SqlConnection conn = SQLAzureUtilities.GetActiveSqlConnection()) using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "AddOrder"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter tenant = cmd.Parameters.Add("@Tenant", SqlDbType.NVarChar); tenant.Value = spContext.SPHostUrl.ToString(); SqlParameter supplier = cmd.Parameters.Add("@Supplier", SqlDbType.NVarChar, 50); supplier.Value = supplierName; SqlParameter itemName = cmd.Parameters.Add("@ItemName", SqlDbType.NVarChar, 50); itemName.Value = productName; SqlParameter quantity = cmd.Parameters.Add("@Quantity", SqlDbType.SmallInt); quantity.Value = quantityOrdered; cmd.ExecuteNonQuery(); } }