/** * * 执行带参数的sql,包括 : 插入、更新、删除 * * */ public bool excute(string sql, Dictionary<string, Object> parameters) { SqlCommand command = null; try { command = new SqlCommand(); command.Connection = conn; command.CommandText = sql; foreach (KeyValuePair<string, Object> param in parameters) { command.Parameters.AddWithValue(param.Key, param.Value); } if (-1 != command.ExecuteNonQuery()) return true; else return false; } catch (Exception e) { MessageBox.Show(e.Message); return false; } finally { if(command != null) command.Dispose(); } }
public Dictionary<string, int> GetLastRefreshNr(String marketIds) { Dictionary<string, int> result = new Dictionary<string, int>(); try { string query = null; using (var ctx = new bfmsEntities()) { query = "SELECT MAX(RefreshNr) as RefreshNr,Marketbook.* from Marketbook where Marketid in (" + marketIds + ") group by marketid"; var RefrNrList = ctx.Database.SqlQuery<marketbook>(query).ToList(); foreach (var row in RefrNrList) { result.Add(row.MarketId, row.RefreshNr); } } } catch (Exception ex) { logger.Fatal(Util.FormatExc(ex)); } return result; }
/// <summary> /// Single Param Constructor for specifying advanced connection options. /// </summary> /// <param name="connectionOpts">A dictionary containing all desired options and their values</param> public SQLiteDatabase(Dictionary<String, String> connectionOpts) { String str = ""; foreach (KeyValuePair<String, String> row in connectionOpts) { str += String.Format("{0}={1}; ", row.Key, row.Value); } str = str.Trim().Substring(0, str.Length - 1); dbConnection = str; }
public ProgressWindow(Dictionary dictionary, string sourceTextPath) { InitializeComponent(); SetLocalization(); wndProgress.Title = Resources["creatingDictionary"].ToString(); FinishedSuccesfull = false; mProgressThread = new Thread(() => { if(ParseDictionaryToSql(dictionary, sourceTextPath)) FinishedSuccesfull = true; Dispatcher.Invoke((Action)(() => this.Close())); }); mProgressThread.Start(); }
static ExportCSV() { reportFields = new Dictionary<string, Dictionary<string, string[]>>(); reportFields.Add("data_account", new Dictionary<string, string[]> { { "month", new string[] { "出账月份", "date", "{0:yyyy-MM}" } }, { "city", new string[] { "地市", "param" } }, { "product", new string[] { "产品", "param" } }, { "type", new string[] { "出账类型", "param" } }, { "money", new string[] { "出账金额", "money" } } }); reportFields.Add("data_cardsale", new Dictionary<string, string[]> { { "date", new string[] { "销售日期", "date", "{0:yyyy-MM-dd}" } }, { "city", new string[] { "地市", "param" } }, { "product", new string[] { "产品", "param" } }, { "number", new string[] { "卡销售数量", "int" } }, { "unit_price", new string[] { "面值金额", "money" } }, { "total_price", new string[] { "总金额", "money" } }, { "final_price", new string[] { "实售金额", "money" } } }); reportFields.Add("data_notice", new Dictionary<string, string[]> { { "date", new string[] { "营业收款日期", "date", "{0:yyyy-MM-dd}" } }, { "city", new string[] { "地市", "param" } }, { "product", new string[] { "产品", "param" } }, { "type", new string[] { "通知单类型", "param" } }, { "money", new string[] { "营业收入金额", "money" } } }); reportFields.Add("data_prestore", new Dictionary<string, string[]> { { "date", new string[] { "销账日期", "date", "{0:yyyy-MM-dd}" } }, { "city", new string[] { "地市", "param" } }, { "product", new string[] { "产品", "param" } }, { "type", new string[] { "销账类型", "param" } }, { "money", new string[] { "销账金额", "money" } } }); reportFields.Add("data_settlement", new Dictionary<string, string[]> { { "month", new string[] { "结算月份", "date", "{0:yyyy-MM}" } }, { "city", new string[] { "地市", "param" } }, { "product", new string[] { "产品", "param" } }, { "operator", new string[] { "结算运营商", "param" } }, { "type", new string[] { "结算类型", "param" } }, { "money", new string[] { "结算金额", "money" } } }); }
public static int CreateDictionary(Dictionary dictionary) { if (string.IsNullOrWhiteSpace(dictionary.Title) || dictionary.Title.Length > 200 || dictionary.Note.Length > 500) return 0; using (SqlConnection connection = Connection.SqlConnection) { using (SqlCommand command = connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = "CreateDictionary"; command.Parameters.AddWithValue("@title", dictionary.Title); command.Parameters.AddWithValue("@termLanguageId", dictionary.TermLanguageId); command.Parameters.AddWithValue("@definitionLanguageId", dictionary.DefinitionLanguageId); command.Parameters.AddWithValue("@note", dictionary.Note); SqlParameter returnedValue = command.Parameters.Add("return", SqlDbType.Int); returnedValue.Direction = ParameterDirection.ReturnValue; command.ExecuteNonQuery(); return (int)returnedValue.Value; } } }
public ActionResult DownloadOrderAsPdf(int id = 0) { string cookieName = OpenIdMembershipService.LOGIN_COOKIE_NAME; HttpCookie cookie = Request.Cookies[cookieName]; Dictionary<string, string> cookies = new Dictionary<string, string>(); cookies.Add(cookieName, cookie.Value); int? historyActionId = null; Order order; using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, id)) using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId)) { order = ordersRep.GetEntity(id); historyActionId = (int)HistoryActions.OrderPrinted; Orders_History orderHistory = new Orders_History(); if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value); } return new ActionAsPdf("PrintOrderToScreen", new { password = PRINT_PASSWORD, id = id, companyId = CurrentUser.CompanyId, userId = CurrentUser.UserId, userRoles = CurrentUser.Roles, languageCode = CurrentUser.LanguageCode, coinSign = CurrentUser.CompanyCoinSign }) { FileName = String.Format("Order_{0}.pdf", order.OrderNumber) }; }
/// <summary> /// Allows the programmer to easily update rows in the DB. /// </summary> /// <param name="tableName">The table to update.</param> /// <param name="data">A dictionary containing Column names and their new values.</param> /// <param name="where">The where clause for the update statement.</param> /// <returns>A boolean true or false to signify success or failure.</returns> public bool Update(String tableName, Dictionary<String, String> data, String where) { String vals = ""; Boolean returnCode = true; if (data.Count >= 1) { foreach (KeyValuePair<String, String> val in data) { vals += String.Format(" {0} = '{1}',", val.Key.ToString(), val.Value.ToString()); } vals = vals.Substring(0, vals.Length - 1); } try { this.ExecuteNonQuery(String.Format("update {0} set {1} where {2};", tableName, vals, where)); } catch { returnCode = false; } return returnCode; }
/// <summary> /// Allows the programmer to easily insert into the DB /// </summary> /// <param name="tableName">The table into which we insert the data.</param> /// <param name="data">A dictionary containing the column names and data for the insert.</param> /// <returns>A boolean true or false to signify success or failure.</returns> public bool Insert(String tableName, Dictionary<String, String> data) { String columns = ""; String values = ""; Boolean returnCode = true; foreach (KeyValuePair<String, String> val in data) { columns += String.Format(" {0},", val.Key.ToString()); values += String.Format(" '{0}',", val.Value); } columns = columns.Substring(0, columns.Length - 1); values = values.Substring(0, values.Length - 1); try { this.ExecuteNonQuery(String.Format("insert into {0}({1}) values({2});", tableName, columns, values)); } catch (Exception fail) { MessageBox.Show(fail.Message); returnCode = false; } return returnCode; }
/// <summary> /// Adds wall data ( Wall, Insulated, Sandwich and Double Wall ) to the ModelBuilderData instance. /// </summary> /// <param name="database"> /// </param> /// <param name="modelBuilderData"> /// </param> /// <param name="elementDictionary"> /// </param> void AddWallData( ImpactDatabase database, ref ModelBuilderData modelBuilderData, ref Dictionary<ElementType.KnownValue, List<Element>> elementDictionary ) { if( null == modelBuilderData ) throw new ArgumentNullException( "data" ); if( null == elementDictionary ) throw new ArgumentNullException( "elementDictionary" ); // No need to continue if the list is empty. if( 0 == elementDictionary.Count ) return; List<Element> tempList = null; List<Element> allList = new List<Element>( 500 ); if( elementDictionary.TryGetValue( ElementType.KnownValue.Wall, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Wall ); } if( elementDictionary.TryGetValue( ElementType.KnownValue.InsulatedWall, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.InsulatedWall ); } if( elementDictionary.TryGetValue( ElementType.KnownValue.Sandwich, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Sandwich ); } if( elementDictionary.TryGetValue( ElementType.KnownValue.DoubleWall, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.DoubleWall ); } // No walls in the project, no need to query the database for more information. if( allList.Count == 0 ) return; // var wallMaterialArgs = new ImpactDatabase.ProfacomArgs<ImpWallStyleStd>( _factory, _project, GetWallMaterialQuery( _company, _factory, _project ), // ImpWallStyleStd.ElementType, // ImpWallStyleStd.Name ); // var wallMaterialList = database.Profacom( wallMaterialArgs, column => new // { // ElementType = ( (ElementType)DataConverter.Cast<string>( column[0] ) ).EnumValue, // Name = DataConverter.Cast<string>( column[1] ), // MaterialName = DataConverter.Cast<string>( column[2] ), // } ); var wallMaterialList = database.GetAll( GetWallMaterialQuery( this._factory, this._project ).ToString(), column => new { ElementMark = column[0].Cast<string>().Trim(), MaterialName = column[1].Cast<string>(), } ); #region Endcap Edges // Get all endcap edges for walls. var endcapEdgeList = database.GetAll( GetEndcapEdgeQuery( this._factory, this._project ), column => new { ElementMark = column[0].Cast<string>().Trim(), EndcapEdge = new EndcapEdge { Side = ( (Side)column[1].Cast<string>() ).EnumValue, StartAt = column[2].Cast<double>(), Length = column[3].Cast<double>(), FromSide = ( (Side)column[4].Cast<string>() ).EnumValue, IndentAtStart = column[5].Cast<double>(), IndentAtEnd = column[6].Cast<double>(), } } ); #endregion Endcap Edges #region Openings // Get all opening standards. ImpactDatabase.ProfacomArgs<ImpOpeningStd> openingArgs = new ImpactDatabase.ProfacomArgs<ImpOpeningStd>( this._factory, this._project, GetOpeningStandardQuery( this._factory, this._project ), ImpOpeningStd.Name ); var openingStandardDictionary = database.Profacom( openingArgs, column => new { Name = column[0].Cast<string>(), Width = column[1].Cast<double>(), Height = column[2].Cast<double>(), } ).ToDictionary( openingStd => openingStd.Name ); var openingStandard = new { Name = string.Empty, Width = 0d, Height = 0d }; // Get all the openings in the project. var openingList = database.GetAll( GetOpeningQuery( this._factory, this._project ).ToString(), column => new { ElementMark = column[0].Cast<string>().Trim(), Name = column[1].Cast<string>(), X = column[2].Cast<double>(), Y = column[3].Cast<double>(), } ); var openingGroupList = ( from n in openingList let isFound = openingStandardDictionary.TryGetValue( n.Name, out openingStandard ) where isFound select new { n.ElementMark, Opening = new Opening { X = n.X, Y = n.Y, Width = openingStandard.Width, Height = openingStandard.Height } } ).GroupBy( x => x.ElementMark, x => x.Opening ).ToList(); #endregion Openings List<WallGeometry> wallList = new List<WallGeometry>( allList.Count ); foreach( var element in allList ) { WallGeometry wall = new WallGeometry( element.Geometry ); // Endcap Edges. wall.EndcapEdges = ( from endcap in endcapEdgeList where element.Geometry.ElementMark == endcap.ElementMark select endcap.EndcapEdge ).ToList(); // Windows and Doors. var openingGroup = openingGroupList.Find( group => group.Key == element.Geometry.ElementMark ); if( null != openingGroup ) { wall.Openings = openingGroup.ToList(); } // Find the material for the wall. var wallMaterial = wallMaterialList.Find( item => item.ElementMark == wall.ElementMark ); if( null != wallMaterial ) { wall.MaterialName = wallMaterial.MaterialName; } wallList.Add( wall ); } // Add the walls to the model builder data. modelBuilderData.Walls = wallList; }
/// <summary> /// The add linked data. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="modelBuilderData"> /// The model builder data. /// </param> /// <param name="elementDictionary"> /// The element dictionary. /// </param> /// <exception cref="ArgumentNullException"> /// </exception> void AddLinkedData( ImpactDatabase database, ref ModelBuilderData modelBuilderData, ref Dictionary<ElementType.KnownValue, List<Element>> elementDictionary ) { if( null == modelBuilderData ) throw new ArgumentNullException( "modelBuilderData" ); if( null == elementDictionary ) throw new ArgumentNullException( "elementDictionary" ); // No need to continue if the list is empty. if( 0 == elementDictionary.Count ) return; List<Element> tempList = null; List<LinkedGeometry> linkedList = new List<LinkedGeometry>( 50 ); if( elementDictionary.TryGetValue( ElementType.KnownValue.Linked, out tempList ) ) { linkedList.AddRange( from item in tempList select new LinkedGeometry( item.Geometry ) ); elementDictionary.Remove( ElementType.KnownValue.Linked ); } if( elementDictionary.TryGetValue( ElementType.KnownValue.PrestressedLinked, out tempList ) ) { linkedList.AddRange( from item in tempList select new LinkedGeometry( item.Geometry ) ); elementDictionary.Remove( ElementType.KnownValue.PrestressedLinked ); } modelBuilderData.Linked = linkedList; }
/// <summary> /// Adds section data ( Beam, Prestressed Beam, Column, Hollow Core and Prestressed Slab ) to the ModelBuilderData instance. /// </summary> /// <param name="database"> /// </param> /// <param name="modelBuilderData"> /// </param> /// <param name="elementDictionary"> /// </param> void AddSectionData( ImpactDatabase database, ref ModelBuilderData modelBuilderData, ref Dictionary<ElementType.KnownValue, List<Element>> elementDictionary ) { if( null == modelBuilderData ) { throw new ArgumentNullException( "data" ); } if( null == elementDictionary ) { throw new ArgumentNullException( "elementDictionary" ); } // No need to continue if the list is empty. if( 0 == elementDictionary.Count ) { return; } List<Element> tempList = null; List<Element> beamList = new List<Element>( 500 ); List<Element> columnList = new List<Element>( 500 ); List<Element> hollowCoreList = new List<Element>( 500 ); List<Element> slabList = new List<Element>( 500 ); List<Element> allList = new List<Element>( 1000 ); bool proceed = false; if( elementDictionary.TryGetValue( ElementType.KnownValue.Beam, out tempList ) ) { beamList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Beam ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.PrestressedBeam, out tempList ) ) { beamList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.PrestressedBeam ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.Column, out tempList ) ) { columnList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Column ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.HollowCore, out tempList ) ) { hollowCoreList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.HollowCore ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.PrestressedSlab, out tempList ) ) { slabList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.PrestressedSlab ); proceed = true; } // No need to query the database if there are no elements. if( false == proceed ) { return; } // Section Parameters. var sectionParameterArgs = new ImpactDatabase.ProfacomArgs<ImpSectionStyleParameterStd>( this._factory, this._project, GetSectionParameterQuery( this._factory, this._project ), ImpSectionStyleParameterStd.ElementType, ImpSectionStyleParameterStd.Name, ImpSectionStyleParameterStd.ParameterId ); var sectionParameterList = database.Profacom( sectionParameterArgs, column => new { ElementType = ( (ElementType) column[0].Cast<string>() ). EnumValue, Name = column[1].Cast<string>(), Parameter = new SectionParameter( DataConverter.Cast <SectionStyleParameter>( column[2] ), column[3].Cast<double>() ) } ); // Section Geometry. var sectionGeometryArgs = new ImpactDatabase.ProfacomArgs<ImpSectionGeometryStd>( this._factory, this._project, GetSectionGeometryQuery( this._factory, this._project ), ImpSectionGeometryStd.ElementType, ImpSectionGeometryStd.Section, ImpSectionGeometryStd.PointId ); var sectionGeometryList = database.Profacom( sectionGeometryArgs, column => new { ElementType = ( (ElementType) column[0].Cast<string>() ). EnumValue, Name = column[1].Cast<string>(), Id = column[2].Cast<int>(), Point = new GeometryPoint { X = column[3].Cast <double>(), Y = column[4].Cast <double>(), Bulge = column[5].Cast <double>() } } ); // Section Core Geometry. var sectionCoreGeometryArgs = new ImpactDatabase.ProfacomArgs<ImpSectionCoreGeometryStd>( this._factory, this._project, GetSectionCoreGeometryQuery( this._factory, this._project ), ImpSectionCoreGeometryStd.ElementType, ImpSectionCoreGeometryStd.Section, ImpSectionCoreGeometryStd.CoreId, ImpSectionCoreGeometryStd.CorePointId ); var sectionCoreGeometryList = database.Profacom( sectionCoreGeometryArgs, column => new { ElementType = ( (ElementType) column[0].Cast<string>() ) .EnumValue, Name = column[1].Cast<string>(), Id = column[2].Cast<int>(), PointId = column[3].Cast<int>(), Point = new GeometryPoint { X = column[4]. Cast <double>(), Y = column[5]. Cast <double>(), Bulge = column[6]. Cast <double>() } } ).GroupBy( item => new { item.ElementType, item.Name, item.Id } ); // Section style and material. var sectionArgs = new ImpactDatabase.ProfacomArgs<ImpSectionStyleStd>( this._factory, this._project, GetSectionStyleQuery( this._company, this._factory, this._project ), ImpSectionStyleStd.ElementType, ImpSectionStyleStd.Name ); var sectionStyleList = database.Profacom( sectionArgs, column => new { ElementType = ( (ElementType)column[0].Cast<string>() ). EnumValue, Name = column[1].Cast<string>(), SectionType = column[2].Cast<string>(), Width = column[3].Cast<double>(), Height = column[4].Cast<double>(), CutType = column[5].Cast<CutType>(), // It is possible that no material was found, in that case // the resulting columns will contain 'null' values. // If the material is missing, we'll set the RGB value // to black ( 0, 0, 0 ). Material = column[6].Cast<string>(), } ); // End Beam angles. var endBeamList = database.GetAll( GetEndBeamQuery( this._factory, this._project ).ToString(), column => new { ElementMark = column [0]. Cast < string >(). Trim(), Side = column [ 1 ] . Cast < int > () == 3 ? Side . KnownValue . Left : Side . KnownValue . Right, Angle = column [2]. Cast < double >(), } ); var sectionList = new List<SectionGeometry>(); foreach( var element in allList ) { var style = sectionStyleList.Find( x => x.ElementType == element.Geometry.ElementType && x.Name == element.Style ); if( null != style ) { var section = new SectionGeometry( element.Geometry ) { SectionType = ( (SectionType)style.SectionType ).EnumValue, CutType = style.CutType, SectionWidth = style.Width, SectionHeight = style.Height, MaterialName = element.Geometry.MaterialName, Parameters = ( from item in sectionParameterList where item.ElementType == style.ElementType && item.Name == style.Name select item.Parameter ).ToDictionary( param => param.Key, param => param.Value ), SectionPoints = ( from item in sectionGeometryList where item.ElementType == style.ElementType && item.Name == style.Name orderby item.Id ascending select item.Point ).ToList(), Cores = ( from item in sectionCoreGeometryList where item.Key.ElementType == style.ElementType && item.Key.Name == style.Name let points = from n in item orderby n.PointId ascending select n.Point orderby item.Key.Id ascending select new CoreGeometry( points.ToList() ) ).ToList() }; sectionList.Add( section ); } else { // If we don't have a style, then we have to create the section as a bounding box. var section = new SectionGeometry( element.Geometry ) { SectionType = SectionType.KnownValue.Invalid, CutType = CutType.Symmetrical, SectionWidth = element.Geometry.Width, SectionHeight = element.Geometry.Height, MaterialName = element.Geometry.MaterialName, }; sectionList.Add( section ); } } // var sectionList = ( from element in allList // let style = sectionStyleList.Find( x => x.ElementType == element.Geometry.ElementType && x.Name == element.Style ) // where null != style // let section = new SectionGeometry( element.Geometry ) // { // SectionType = ( (SectionType)style.SectionType ).EnumValue, // CutType = style.CutType, // SectionWidth = style.Width, // SectionHeight = style.Height, // MaterialName = style.Material, // Parameters = ( from item in sectionParameterList // where item.ElementType == style.ElementType // && item.Name == style.Name // select item.Parameter ).ToDictionary( param => param.Key, param => param.Value ), // SectionPoints = ( from item in sectionGeometryList // where item.ElementType == style.ElementType // && item.Name == style.Name // orderby item.Id ascending // select item.Point ).ToList(), // Cores = ( from item in sectionCoreGeometryList // where item.Key.ElementType == style.ElementType // && item.Key.Name == style.Name // let points = ( from n in item orderby n.PointId ascending select n.Point ) // orderby item.Key.Id ascending // select new CoreGeometry( points.ToList() ) ).ToList() // } // select section ).ToList(); foreach( var item in sectionList ) { switch( item.ElementType ) { case ElementType.KnownValue.Beam: case ElementType.KnownValue.PrestressedBeam: { // Because the height parameter might be missing in the database, // we add it explicitly here. item.Parameters[SectionStyleParameter.H] = item.Height; var beam = new BeamGeometry( item ); // Check if the beam has an left vertical angle. var endBeamItem = endBeamList.Find( endBeam => endBeam.ElementMark == beam.ElementMark && endBeam.Side == Side.KnownValue.Left ); // Set the left vertical angle. if( null != endBeamItem ) { beam.VerticalAngleLeft = endBeamItem.Angle; } // Check if the beam has an right vertical angle. endBeamItem = endBeamList.Find( endBeam => endBeam.ElementMark == beam.ElementMark && endBeam.Side == Side.KnownValue.Right ); // Set the right vertical angle. if( null != endBeamItem ) { beam.VerticalAngleRight = endBeamItem.Angle; } modelBuilderData.Beams.Add( beam ); break; } case ElementType.KnownValue.Column: { // Because the height parameter might be missing in the database, // we add it explicitly here. item.Parameters[SectionStyleParameter.H] = item.Height; modelBuilderData.Columns.Add( item ); break; } case ElementType.KnownValue.HollowCore: { modelBuilderData.HollowCores.Add( item ); break; } case ElementType.KnownValue.PrestressedSlab: { modelBuilderData.PrestressedSlabs.Add( item ); break; } default: break; } } }
/// <summary> /// Adds slab data ( Slab, Form Slab, and Prestressed Form Slab ) to the ModelBuilderData instance. /// </summary> /// <param name="database"> /// </param> /// <param name="modelBuilderData"> /// </param> /// <param name="elementDictionary"> /// </param> void AddSlabData( ImpactDatabase database, ref ModelBuilderData modelBuilderData, ref Dictionary<ElementType.KnownValue, List<Element>> elementDictionary ) { if( null == modelBuilderData ) throw new ArgumentNullException( "data" ); if( null == elementDictionary ) throw new ArgumentNullException( "elementDictionary" ); // No need to continue if the list is empty. if( 0 == elementDictionary.Count ) return; List<Element> tempList = null; List<Element> allList = new List<Element>( 500 ); if( elementDictionary.TryGetValue( ElementType.KnownValue.Slab, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Slab ); } if( elementDictionary.TryGetValue( ElementType.KnownValue.FormSlab, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.FormSlab ); } if( elementDictionary.TryGetValue( ElementType.KnownValue.PrestressedFormSlab, out tempList ) ) { allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.PrestressedFormSlab ); } if( allList.Count == 0 ) return; List<SlabGeometry> slabList = new List<SlabGeometry>( allList.Count ); foreach( var element in allList ) { SlabGeometry slab = new SlabGeometry( element.Geometry ); slabList.Add( slab ); } // Add the walls to the model builder data. modelBuilderData.Slabs = slabList; }
private bool ParseDictionaryToSql(Dictionary dictionary, string sourceTextPath ) { if (string.IsNullOrWhiteSpace(dictionary.Title) || dictionary.TermLanguageId<1 || dictionary.DefinitionLanguageId<1) return false; int dictionaryId = DB.Dictionary.CreateDictionary(dictionary); if (dictionaryId == 0) return false; //Create a new instance of ProgressBar Delegate that points // to the ProgressBar's SetValue method. UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(pbProgress.SetValue); Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, 0.0 }); String source = File.ReadAllText(sourceTextPath, Encoding.UTF8); string[] chunks = source.Split(new string[] { "<k>" }, StringSplitOptions.None); List<Article> articles = new List<Article>(); Dispatcher.Invoke((Action)(() => pbProgress.Maximum = chunks.Count())); int counter = 0; Parallel.ForEach(chunks, chunk => { Interlocked.Increment(ref counter); StringBuilder text = new StringBuilder(chunk); text.Replace("<opt>", "["); text.Replace("</opt>", "]"); text.Replace("<nu />", ""); text = new StringBuilder(Regex.Replace(text.ToString(), @"<rref>.*</rref>", " ")); text = new StringBuilder(Regex.Replace(text.ToString(), @"<iref>.*</iref>", " ")); text = new StringBuilder(Regex.Replace(text.ToString(), @"•\s+<kref>", "- <kref>")); text = new StringBuilder(Regex.Replace(text.ToString(), @"\- <kref>.*</kref>", "")); string output = text.ToString(); output = Regex.Replace(output, @"\)\s*\n", ") "); output = Regex.Replace(output, @"•", " "); output = output.Replace("<k>", "\n<k>"); output = output.Replace("<tr>", "\n<tr>"); output = output.Replace("<ex>", "\n<ex>"); output = Regex.Replace(output, @"\s+\n+", " \n"); StringWriter myWriter = new StringWriter(); // Decode the encoded string. HttpUtility.HtmlDecode(output, myWriter); output = myWriter.ToString(); StringBuilder article = new StringBuilder(output); Regex tagsRegex = new Regex(@"<((\w+)|(/\w+)|( /\w+)|\w+ /)>"); string addedWord = Regex.Match(output, @".*</k>").ToString(); if (!string.IsNullOrWhiteSpace(addedWord)) article.Replace(addedWord, ""); if (string.IsNullOrWhiteSpace(addedWord) || addedWord.Contains("#ICON_FILE")) return; addedWord = tagsRegex.Replace(addedWord, ""); HashSet<string> uniqueTranscriptions = new HashSet<string>(); foreach (Match m in Regex.Matches(output, @"<tr>.*</tr>")) { uniqueTranscriptions.Add(tagsRegex.Replace(m.ToString(), "")); article.Replace(m.ToString(), ""); } StringBuilder transcription = new StringBuilder(); foreach (string tr in uniqueTranscriptions) { transcription.Append(tr).Append(" "); } string example = null; foreach (Match m in Regex.Matches(article.ToString(), @"<ex>.*</ex>")) { example = tagsRegex.Replace(m.ToString(), ""); example = Regex.Replace(example, " ; ", " "); article.Replace(m.ToString(), ""); } if (example != null) example = example.Trim(); string transl = tagsRegex.Replace(article.ToString(), ""); transl = Regex.Replace(transl, @"\s+\n+", " \n"); lock(articles) { articles.Add(new Article(0, dictionaryId, addedWord.Trim(), transcription.ToString().Trim(), transl.Trim(), example)); Debug.Print("{0}/{1}", counter, chunks.Count()); if (articles.Count > 50) // "|| counter==end" can lead to data loss { DB.Dictionaries.AddDictionariesContent(articles); articles.Clear(); Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, (double)counter }); } } }); //if previous condition didn't work //do not remove! if (articles.Count > 0) { DB.Dictionaries.AddDictionariesContent(articles); articles.Clear(); Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, (double)counter }); Debug.Print("Safety net"); } return true; }
/** * * 执行带参数的查询 * * */ public SqlCeDataReader excuteSqlCeQuery(string sql, Dictionary<string, Object> parameters) { return null; }
/** * * 执行带参数的查询 * * */ public SqlDataReader excuteQuery(string sql, Dictionary<string, Object> parameters) { SqlCommand command = null; try { command = new SqlCommand(); command.Connection = conn; command.CommandText = sql; foreach (KeyValuePair<string, Object> param in parameters) { command.Parameters.AddWithValue(param.Key, param.Value); } return command.ExecuteReader(); } catch (Exception e) { MessageBox.Show(e.Message); return null; } finally { if (command != null) command.Dispose(); } }