public bool SaveODBC() { string fileFullName = null ; string tableName = null ; OnSetConnectionInfo(ref fileFullName ,ref tableName ) ; if ( fileFullName == null || tableName == null ) return false ; ODBCDataSave saveData = new ODBCDataSave(fileFullName, tableName ) ; /// table에 맞는 field와 type을 정의 한다. int , real ,text 이렇게 3개만 현재 지원하게 코드 되어 있다. /// 만약 short 을 쓰고 있다면 int형으로 넘기고 short형으로 형변환 하면 된다. OnAddFieldInfo(saveData) ; /// field 추가가 완료 되면 이 함수를 호출 해야 한다. saveData.CompleteAddField() ; /// 기입될 데이타를 List에 추가한다. OnAddSaveData(saveData) ; /// access에 저장한다. if ( !ODBCHelper.Save(saveData,ODBCHelper.ODBC_TYPE.EXCEL) ) { Debug.Log( " error save ") ; return false ; } return true ; }
static public bool CreateDataToExcelFromBlankExcel(ODBCDataSave saveData,string copyPath ,ODBC_TYPE type) { ODBCBase odbc = null ; odbc = GetODBC(type) ; try { File.Delete(saveData.FileFullName) ; File.Copy(copyPath,saveData.FileFullName) ; } catch( Exception e ) { Debug.LogError(e.ToString()) ; return false ; } if ( odbc.Connection(saveData.FileFullName ) ) { if ( odbc.CreateTable(saveData) && odbc.Insert(saveData) ) { odbc.Close() ; return true ; } } return true ; }
static public bool CreateDataToExcelFromBlankExcel(ODBCDataSave saveData, string copyPath, ODBC_TYPE type) { ODBCBase odbc = null; odbc = GetODBC(type); try { File.Delete(saveData.FileFullName); File.Copy(copyPath, saveData.FileFullName); } catch (Exception e) { Debug.LogError(e.ToString()); return(false); } if (odbc.Connection(saveData.FileFullName)) { if (odbc.CreateTable(saveData) && odbc.Insert(saveData)) { odbc.Close(); return(true); } } return(true); }
public bool SaveODBC() { string fileFullName = null; string tableName = null; OnSetConnectionInfo(ref fileFullName, ref tableName); if (fileFullName == null || tableName == null) { return(false); } ODBCDataSave saveData = new ODBCDataSave(fileFullName, tableName); /// table에 맞는 field와 type을 정의 한다. int , real ,text 이렇게 3개만 현재 지원하게 코드 되어 있다. /// 만약 short 을 쓰고 있다면 int형으로 넘기고 short형으로 형변환 하면 된다. OnAddFieldInfo(saveData); /// field 추가가 완료 되면 이 함수를 호출 해야 한다. saveData.CompleteAddField(); /// 기입될 데이타를 List에 추가한다. OnAddSaveData(saveData); /// access에 저장한다. if (!ODBCHelper.Save(saveData, ODBCHelper.ODBC_TYPE.EXCEL)) { Debug.Log(" error save "); return(false); } return(true); }
static public bool Save(ODBCDataSave saveData , ODBC_TYPE type) { ODBCBase odbc = null ; odbc = GetODBC(type) ; if ( !odbc.Save(saveData) ) return false ; return true ; }
static public bool Save(ODBCDataSave saveData, ODBC_TYPE type) { ODBCBase odbc = null; odbc = GetODBC(type); if (!odbc.Save(saveData)) { return(false); } return(true); }
public bool Save(ODBCDataSave saveData) { if (Connection(saveData.FileFullName) && DeleteAll(saveData.TableName) && Insert(saveData)) { Close(); return(true); } return(false); }
public bool CreateTable(ODBCDataSave myODBCDataSave) { //string yourQuery = "CREATE TABLE tableName ( MyName VARCHAR (30), MyNumber integer )"; StringBuilder query = new StringBuilder(); StringBuilder filed = new StringBuilder(); query.Append("CREATE TABLE " + myODBCDataSave.TableName); filed.Append(" ( "); if (myODBCDataSave.FieldList.Count > 0) { filed.Append(myODBCDataSave.FieldList[0].FieldName); filed.Append(GetFiledTypeString(myODBCDataSave.FieldList[0].Type)); } for (int i = 1; i < myODBCDataSave.FieldList.Count; i++) { filed.Append(" , " + myODBCDataSave.FieldList[i].FieldName); filed.Append(GetFiledTypeString(myODBCDataSave.FieldList[i].Type)); } filed.Append(" ) "); query.Append(filed); try { OdbcCommand cmd = new OdbcCommand(query.ToString(), connection); cmd.ExecuteNonQuery(); } catch (Exception ex) { Debug.Log(ex.ToString()); Close(); return(false); } return(true); }
public override void OnAddFieldInfo(ODBCDataSave saveData) { }
abstract public void OnAddSaveData(ODBCDataSave saveData);
abstract public void OnAddFieldInfo(ODBCDataSave saveData);
public override void OnAddSaveData(ODBCDataSave saveData) { }
public bool Insert(ODBCDataSave myODBCDataSave) { StringBuilder query = new StringBuilder() ; StringBuilder filed = new StringBuilder() ; StringBuilder values = new StringBuilder() ; query.Append( "INSERT INTO " + OnGetTableName(myODBCDataSave.TableName) ) ; filed.Append(" (" ) ; values.Append(" (" ) ; if ( myODBCDataSave.FieldList.Count > 0 ) { filed.Append( myODBCDataSave.FieldList[0].FieldName ) ; values.Append( "?" ) ; } for ( int i = 1 ; i < myODBCDataSave.FieldList.Count ; i++ ) { filed.Append( "," + myODBCDataSave.FieldList[i].FieldName ) ; values.Append( ",?" ) ; } filed.Append(") " ) ; values.Append(") " ) ; query.Append(filed) ; query.Append(" VALUES " ) ; query.Append(values + " " ) ; try { OdbcCommand cmd = new OdbcCommand() ; cmd.Connection = connection ; for ( int i = 0 ; i < myODBCDataSave.FieldList.Count ; i++ ) { OdbcParameter para = new OdbcParameter(i.ToString(),myODBCDataSave.FieldList[i].Type); cmd.Parameters.Add(para) ; } foreach ( List<object> datas in myODBCDataSave.DataList ) { for ( int i = 0 ; i < myODBCDataSave.FieldList.Count ; i++ ) cmd.Parameters[i].Value = datas[i].ToString() ; cmd.CommandText = query.ToString() ; cmd.ExecuteNonQuery() ; } } catch( Exception ex ) { Debug.Log( ex.ToString() ) ; Close() ; return false ; } return true ; }
public bool Save(ODBCDataSave saveData) { if ( Connection(saveData.FileFullName ) && DeleteAll(saveData.TableName) && Insert(saveData) ) { Close() ; return true ; } return false ; }
public bool CreateTable(ODBCDataSave myODBCDataSave) { //string yourQuery = "CREATE TABLE tableName ( MyName VARCHAR (30), MyNumber integer )"; StringBuilder query = new StringBuilder() ; StringBuilder filed = new StringBuilder() ; query.Append( "CREATE TABLE " + myODBCDataSave.TableName ) ; filed.Append( " ( " ) ; if ( myODBCDataSave.FieldList.Count > 0 ) { filed.Append( myODBCDataSave.FieldList[0].FieldName ) ; filed.Append( GetFiledTypeString(myODBCDataSave.FieldList[0].Type ) ) ; } for ( int i = 1 ; i < myODBCDataSave.FieldList.Count ; i++ ) { filed.Append( " , " + myODBCDataSave.FieldList[i].FieldName ) ; filed.Append( GetFiledTypeString(myODBCDataSave.FieldList[i].Type ) ) ; } filed.Append( " ) " ) ; query.Append(filed) ; try { OdbcCommand cmd = new OdbcCommand(query.ToString() , connection); cmd.ExecuteNonQuery() ; } catch( Exception ex ) { Debug.Log( ex.ToString() ) ; Close() ; return false ; } return true ; }
abstract public void OnAddFieldInfo(ODBCDataSave saveData) ;
public bool Insert(ODBCDataSave myODBCDataSave) { StringBuilder query = new StringBuilder(); StringBuilder filed = new StringBuilder(); StringBuilder values = new StringBuilder(); query.Append("INSERT INTO " + OnGetTableName(myODBCDataSave.TableName)); filed.Append(" ("); values.Append(" ("); if (myODBCDataSave.FieldList.Count > 0) { filed.Append(myODBCDataSave.FieldList[0].FieldName); values.Append("?"); } for (int i = 1; i < myODBCDataSave.FieldList.Count; i++) { filed.Append("," + myODBCDataSave.FieldList[i].FieldName); values.Append(",?"); } filed.Append(") "); values.Append(") "); query.Append(filed); query.Append(" VALUES "); query.Append(values + " "); try { OdbcCommand cmd = new OdbcCommand(); cmd.Connection = connection; for (int i = 0; i < myODBCDataSave.FieldList.Count; i++) { OdbcParameter para = new OdbcParameter(i.ToString(), myODBCDataSave.FieldList[i].Type); cmd.Parameters.Add(para); } foreach (List <object> datas in myODBCDataSave.DataList) { for (int i = 0; i < myODBCDataSave.FieldList.Count; i++) { cmd.Parameters[i].Value = datas[i].ToString(); } cmd.CommandText = query.ToString(); cmd.ExecuteNonQuery(); } } catch (Exception ex) { Debug.Log(ex.ToString()); Close(); return(false); } return(true); }
abstract public void OnAddSaveData(ODBCDataSave saveData) ;