public void FormatAndSerialize() { HashSet <Student> studentsData = new HashSet <Student>(new StudentsComparator()); var fileInfo = new FileInfo(pathIn); using (var streamReader = new StreamReader(fileInfo.OpenRead())) { string line = null; while ((line = streamReader.ReadLine()) != null) { string[] columns = line.Split(','); if (!TableChecker <string> .CheckLength(columns, 9)) { Logger.SaveErrorMessageToFile(new ArgumentException(line)); continue; } for (int i = 0; i < columns.Length; i++) { if (TableChecker <string> .CheckColumn(columns[i])) { Logger.SaveErrorMessageToFile(new ArgumentException("Puste kolumny w linii: " + line)); continue; } } var student = new Student { Name = columns[0], Surname = columns[1], TypeOfStudy = columns[2], NameOfStudy = columns[3], Id = columns[4], BirthDay = columns[5], Email = columns[6], MothersName = columns[7], FathersName = columns[8] }; if (!studentsData.Add(student)) { Logger.SaveErrorMessageToFile(new DuplicateNameException("duplikat studenta!")); } } var studentList = new List <Student>(studentsData); if (format.Equals("xml")) { Writer <Student> .WriteDataToXML(pathOut, studentList, "uczelnia"); } else if (format.Equals("json")) { Writer <Student> .WriteDataToJson(pathOut, studentList); } else { Logger.SaveErrorMessageToFile(new FormatException("Format nieobsługiwany")); } } }
private void FrmAllTables_Load(object sender, EventArgs e) { this.Text += ToolVersionInfo.ToolVerInfo; gvTables.AutoGenerateColumns = false; DBInfo info = DbInfo.CreateDBInfo(); _curLst = TableChecker.GetAllTables(info); gvTables.AllowUserToOrderColumns = true; RefreashTablesInfo(); FillBaseType(); }
/// <summary> /// /// </summary> /// <param name="conn"></param> /// <param name="client"></param> /// <param name="filename"></param> /// <param name="tablename"></param> /// <returns></returns> public bool ImportDesiredVariables(DbConnection conn, IDataClient client, string filename, string tablename) { if ((string.IsNullOrEmpty(filename)) || (!File.Exists(filename))) { _log.DebugFormat("ImportDesiredVariables failed: provided filename was empty or did not exist \"{0}\" ", filename); return(false); } try { //empty/create our temporary table DataTable dt = SetupTable(conn, client, tablename); //get a list of the columns they wanted dt = ReadVariablesFile(filename, dt); //check all our error scenarios TableChecker[] fnList = new TableChecker[] { CheckForMaxColumns, CheckForMinColumns, CheckForDuplicates, CheckForMOEDuplicates, CheckForReserved }; bool noErrors = true; foreach (var errCheckFn in fnList) { string msg = errCheckFn(dt); if (!string.IsNullOrEmpty(msg)) { noErrors = false; _log.Error(msg); } } if (!noErrors) { return(false); } SaveTable(conn, client, dt); return(true); } catch (Exception ex) { _log.Error("Variable Import Failed", ex); RemoveTemporaryTable(conn, client); } return(false); }
private void btnSubmit_Click(object sender, EventArgs e) { IEnumerable <DBTableInfo> lst = gvTables.DataSource as IEnumerable <DBTableInfo>; if (lst == null) { return; } List <string> selection = new List <string>(); foreach (DBTableInfo info in lst) { if (info.IsGenerate) { selection.Add(info.Name); } } DBInfo db = DbInfo.CreateDBInfo(); using (BatchAction ba = db.DefaultOperate.StarBatchAction()) { using (FrmProcess frmPro = FrmProcess.ShowProcess()) { string file = DesignerInfo.SelectDocView.DocData.FileName; XmlDocument doc = DBEntityInfo.GetClassDiagram(file); frmPro.UpdateProgress(0, 10, "正在读取类信息"); List <DBTableInfo> lstGen = TableChecker.GetTableInfo(db, selection); string entityNamespace = DesignerInfo.GetNameSpace(); for (int i = 0; i < lstGen.Count; i++) { frmPro.UpdateProgress(i, lstGen.Count, "正在生成"); string baseType = cmbBaseType.Text; if (string.IsNullOrEmpty(baseType)) { baseType = GetDefaultBaseType(); } DBEntityInfo info = new DBEntityInfo(entityNamespace, lstGen[i], DesignerInfo, DbInfo, baseType); info.GreanCode(doc); } //拷贝备份 File.Copy(file, file + ".bak", true); EntityMappingConfig.SaveXML(file, doc); } } this.Close(); }
/// <summary> /// 获取类的创建语句 /// </summary> /// <param name="type"></param> private void GetClassSQL() { _lstSql = new List <string>(); List <KeyWordTableParamItem> lstTable = new List <KeyWordTableParamItem>(); DBConfigInfo dbcinfo = FrmDBSetting.GetDBConfigInfo(DesignerInfo, "DataAccess."); DBInfo dbInfo = dbcinfo.CreateDBInfo(); foreach (ClrClass curType in SelectedClass) { EntityConfig entity = new EntityConfig(curType, DesignerInfo); if (string.IsNullOrEmpty(entity.TableName) || !entity.IsTable) { continue; } string typeName = null; Stack <EntityConfig> stkConfig = EntityConfig.GetEntity(entity, DesignerInfo); List <EntityParam> lstParam = new List <EntityParam>(); List <TableRelationAttribute> lstRelation = new List <TableRelationAttribute>(); string lastTableName = null; string lastSummary = null; while (stkConfig.Count > 0) { EntityConfig centity = stkConfig.Pop(); FillParams(centity, lstParam, lstRelation); lastTableName = centity.TableName; lastSummary = centity.Summary; } KeyWordTableParamItem table = new KeyWordTableParamItem(lstParam, lstRelation, lastTableName, null); table.Description = lastSummary; lstTable.Add(table); } try { using (BatchAction ba = dbInfo.DefaultOperate.StarBatchAction()) { _lstSql = TableChecker.CheckTable(dbInfo, lstTable); } } catch (Exception ex) { MessageBox.Show("生成语句失败:" + ex.Message); } ShowSql(); }
/// <summary> /// 更新类信息 /// </summary> /// <param name="ctype"></param> /// <param name="project"></param> /// <param name="currentDiagram"></param> /// <returns></returns> public static EntityConfig GetEntityConfigByTable(ClrType ctype, ClassDesignerInfo desinfo) { EntityConfig entity = new EntityConfig(ctype, desinfo); //entity.DesignerInfo.SelectDocView = selectDocView; if (string.IsNullOrEmpty(entity.TableName)) { return(null); } DBInfo db = entity.DbInfo.CreateDBInfo(); List <string> selTab = new List <string>(); selTab.Add(entity.TableName); List <DBTableInfo> lstGen = TableChecker.GetTableInfo(db, selTab); if (lstGen.Count > 0) { DBTableInfo info = lstGen[0]; Dictionary <string, EntityParamField> dicParam = entity.GetParamMapField(); entity._dbParams = new List <EntityParam>(); foreach (EntityParam prm in info.Params) { string paramName = prm.ParamName; if (dicParam.ContainsKey(paramName)) { continue; } entity._dbParams.Add(prm); } Dictionary <string, EntityRelationItem> dicRelation = entity.GetRelationmMapField(); entity._dbRelations = new List <TableRelationAttribute>(); foreach (TableRelationAttribute tr in info.RelationItems) { string key = EntityFieldBase.ToPascalName(tr.TargetTable) + ":" + EntityFieldBase.ToPascalName(tr.SourceName) + ":" + EntityFieldBase.ToPascalName(tr.TargetName); if (dicRelation.ContainsKey(key)) { continue; } entity._dbRelations.Add(tr); } } return(entity); }
public (bool, int) CheckPlayerInput(Dictionary <int, Dictionary <Player, TextBox[]> > allPlayersChoice) { TableChecker tableChecker = new TableChecker(); return(tableChecker.CheckPlayerInfo(allPlayersChoice)); }
/// <summary> /// /// </summary> /// <param name="conn"></param> /// <param name="client"></param> /// <param name="filename"></param> /// <param name="tablename"></param> /// <returns></returns> public bool ImportDesiredVariables(DbConnection conn, IDataClient client, string filename, string tablename) { if ((string.IsNullOrEmpty(filename)) || (!File.Exists(filename))) { _log.DebugFormat("ImportDesiredVariables failed: provided filename was empty or did not exist \"{0}\" ", filename); return false; } try { //empty/create our temporary table DataTable dt = SetupTable(conn, client, tablename); //get a list of the columns they wanted dt = ReadVariablesFile(filename, dt); //check all our error scenarios TableChecker[] fnList = new TableChecker[] { CheckForMaxColumns, CheckForMinColumns, CheckForDuplicates, CheckForMOEDuplicates, CheckForReserved }; bool noErrors = true; foreach (var errCheckFn in fnList) { string msg = errCheckFn(dt); if (!string.IsNullOrEmpty(msg)) { noErrors = false; _log.Error(msg); } } if (!noErrors) { return false; } SaveTable(conn, client, dt); return true; } catch (Exception ex) { _log.Error("Variable Import Failed", ex); RemoveTemporaryTable(conn, client); } return false; }
public string DisplayInfo(KeyWordInfomation info, string tableName) { StringBuilder sb = new StringBuilder(); IDBAdapter idba = info.DBInfo.CurrentDbAdapter; bool isPrimary = EnumUnit.ContainerValue((int)_propertyType, (int)EntityPropertyType.PrimaryKey); bool isAutoIdentity = EnumUnit.ContainerValue((int)_propertyType, (int)EntityPropertyType.Identity); bool needIdentity = false; bool putType = true; sb.Append(idba.FormatParam(ParamName) + " "); if (isAutoIdentity && TableChecker.IsIdentityType(SqlType)) { if (idba.IdentityIsType) { sb.Append(idba.DBIdentity(tableName, _paramName)); sb.Append(" "); putType = false; } else { needIdentity = true; } } if (putType) { sb.Append(idba.DBTypeToSQL(SqlType, Length) + " "); } bool allowNULL = _allowNull & (!isPrimary); //if (isPrimary) //{ // sb.Append(" primary key "); //} //else //{ if (isPrimary && info.PrimaryKeys == 1) { sb.Append(" PRIMARY KEY "); } else { if (allowNULL) { sb.Append("NULL "); } else { sb.Append("NOT NULL "); } } //} if (needIdentity && isAutoIdentity && TableChecker.IsIdentityType(SqlType)) { sb.Append(idba.DBIdentity(tableName, _paramName)); } string comment = idba.GetColumnDescriptionSQL(this, info.DBInfo); if (!string.IsNullOrEmpty(comment)) { sb.Append(" "); sb.Append(comment); } return(sb.ToString()); }