/// <summary> /// Checks the property is exist or not in ExcelTableEntity /// </summary> /// <param name="strProperName"></param> /// <param name="strValue"></param> /// <param name="entity"></param> /// <returns></returns> private bool CheckPropertyExist(string strProperName, string strValue, ExcelTableEntity entity) { bool bln_Result = false; try { Type entityType = typeof(ExcelTableEntity); PropertyInfo[] ProList = entityType.GetProperties(); for (int i = 0; i < ProList.Count(); i++) { if (ProList[i].Name == strProperName) { if (ProList[i].PropertyType.Name == "DateTimeOffset") { DateTime dtime = Convert.ToDateTime(strValue); dtime = DateTime.SpecifyKind(dtime, DateTimeKind.Utc); DateTimeOffset utcTime2 = dtime; ProList[i].SetValue(entity, utcTime2); } else { ProList[i].SetValue(entity, strValue); } bln_Result = true; break; } } } catch (Exception ex) { throw ex; } return(bln_Result); }
/// <summary> /// Imports data of DataTable to table storage /// </summary> /// <param name="dtSheetInfo"></param> /// <param name="strSheetName"></param> private void ImportDataToTable(System.Data.DataTable dtSheetInfo, string strSheetName) { try { tbl_TableDetailList.Rows.Clear(); for (int j = 0; j < dtSheetInfo.Rows.Count; j++) { ExcelTableEntity entity = new ExcelTableEntity(strSheetName, DateTime.Now.ToLongTimeString()); for (int i = 0; i < dtSheetInfo.Columns.Count; i++) { string strCloName = dtSheetInfo.Columns[i].ColumnName; if (!(dtSheetInfo.Rows[j][i] is DBNull) && (dtSheetInfo.Rows[j][i] != null)) { string strValue = dtSheetInfo.Rows[j][i].ToString(); if (!CheckPropertyExist(strCloName, strValue, entity)) { EntityProperty property = entity.ConvertToEntityProperty(strCloName, dtSheetInfo.Rows[j][i]); if (!entity.properties.ContainsKey(strCloName)) { entity.properties.Add(strCloName, property); } else { entity.properties[strCloName] = property; } } } } var client = storageAccount.CreateCloudTableClient(); string strTableName = txt_TableName.Text; if (!string.IsNullOrEmpty(strTableName)) { CloudTable table = client.GetTableReference(strTableName); table.CreateIfNotExists(); if (!CheckTableEntityDataExist(entity, table)) { table.Execute(TableOperation.Insert(entity)); } else { table.Execute(TableOperation.InsertOrMerge(entity)); } } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Checks ExcelTableEntity is exist or not in table storage /// </summary> /// <param name="entity"></param> /// <param name="ctTable"></param> /// <returns></returns> private bool CheckTableEntityDataExist(ExcelTableEntity entity, CloudTable ctTable) { bool bln_Result = false; try { string strPartitionKey = entity.PartitionKey; string strRowKey = entity.RowKey; string strFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, strPartitionKey) + " and " + TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, strRowKey); TableQuery <ExcelTableEntity> query = new TableQuery <ExcelTableEntity>().Where(strFilter); if (ctTable.ExecuteQuery(query).Count() > 0) { bln_Result = true; } } catch (Exception ex) { throw ex; } return(bln_Result); }