// NavGroups : ngSearch // private void ngSearch_Find_LinkPressed(object sender, NavBarLinkEventArgs e) { GridView view = GetViewFromSelectedTabPage(); if (view == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst")); return; } view.ShowFindPanel(); }
private void ngFile_Save_LinkPressed(object sender, NavBarLinkEventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; if (SaveFile(fileName)) { } }
private void ngFile_SaveAs_LinkClicked(object sender, NavBarLinkEventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; using (frmSaveAs encSelect = new frmSaveAs(fileName)) { encSelect.ShowDialog(); } }
private void nbiSqlExport_LinkPressed(object sender, NavBarLinkEventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; using (frmExportAsSQL export = new frmExportAsSQL(fileName)) { export.ShowDialog(); } }
private void deleteRowToolStripMenuItem_Click(object sender, EventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; var tbl = StaticReference.GetTableByFullName(fileName); GridView view = GetViewFromSelectedTabPage(); if (view == null || tbl == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst")); return; } if (view.SelectedRowsCount == 0) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoRowsSelected")); return; } if (StaticReference.ShowQuestion(this, string.Format(LanguageManager.Get("Message_DeleteConfirm"), view.SelectedRowsCount)) == DialogResult.Yes) { List <DataRow> selectedRows = new List <DataRow>(); for (int i = 0; i < view.SelectedRowsCount; i++) { selectedRows.Add(tbl.Table.Rows[view.GetSelectedRows()[i]]); } if (_editedCells.ContainsKey(view)) { foreach (var q in view.GetSelectedRows()) { _editedCells[view].RemoveAll(i => i.Key == q); } view.Invalidate(); } foreach (var t in selectedRows) { tbl.Table.Rows.Remove(t); RemoveNewRowHighlight(view, t); } view.ClearSelection(); StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_DeleteSuccess"), selectedRows.Count)); } }
private void ngSearch_FindAndReplace_LinkPressed(object sender, NavBarLinkEventArgs e) { GridView view = GetViewFromSelectedTabPage(); if (view == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst")); return; } using (frmFindAndReplace far = new frmFindAndReplace(this, view)) { far.ShowDialog(); } }
private void btnDebug_Click(object sender, EventArgs e) { SHA256 mySHA256 = SHA256Managed.Create(); var key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes("Q3QgesV4wMug5ZtS7DenWAw3")); StaticReference.ShowWarning(this, BitConverter.ToString(key)); var iv = new byte[16] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; var result = KODevLoginManager.EncryptString("wowowowowharam", key, iv); StaticReference.ShowError(this, result); //RegistrySettings.Load(); // RegistrySettings.Save(); }
private void btnRemoveChecked_Click(object sender, EventArgs e) { if (clbColumns.CheckedItems.Count == 0) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoCheckedItems")); return; } foreach (CheckedListBoxItem v in clbColumns.CheckedItems) { string[] zzz = Convert.ToString(v.Value).Split(','); int ind = Convert.ToInt32(zzz[0]); _tbl.Table.Columns.RemoveAt(ind); // v // Columnindex = 0; } PopulateColumns(); }
private void ngEdit_NewRow_LinkPressed(object sender, NavBarLinkEventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; KOTableFile tbl = StaticReference.GetTableByFullName(fileName); var view = GetViewFromSelectedTabPage(); var row = tbl.Table.NewRow(); tbl.Table.Rows.Add(row); AddNewRowHighlight(view, row); view.FocusedRowHandle = view.RowCount - 1; view.TopRowIndex = view.RowCount - 1; view.RefreshData(); view.Invalidate(); }
private void btnStart_Click(object sender, EventArgs e) { if (_loadedTables.Count == 0) { StaticReference.ShowWarning(this, "There are no loaded tables to convert."); return; } if (string.IsNullOrEmpty(_destinationFolder)) { StaticReference.ShowWarning(this, "Destination folder is not set."); return; } if (!Directory.Exists(_destinationFolder)) { try { Directory.CreateDirectory(_destinationFolder); } catch (Exception ex) { StaticReference.ShowWarning(this, $"An exception occured while creating destination directory.\nException : {ex.Message}"); return; } } var encMethod = StaticReference.EncryptionMethods.FirstOrDefault(v => string.Compare(v.Name(), cbEncryption.Text, StringComparison.Ordinal) == 0); if (encMethod == null) { StaticReference.ShowWarning(this, $"Encryption load error."); return; } foreach (var tbl in _loadedTables) { meLog.Text += $"Saving {_destinationFolder}\\{tbl.Value.Name}" + Environment.NewLine; tbl.Value.SetEncryption(encMethod); tbl.Value.SaveAs($"{_destinationFolder}\\{tbl.Value.Name}"); } StaticReference.ShowInformation(this, "Done."); }
private void btnUpdateColumn_Click(object sender, EventArgs e) { if (clbColumns.CheckedItems.Count == 0) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoCheckedItems")); return; } Type tp = _dataTypeList[cbColumnDataType_Update.SelectedIndex]; DataTable dtCloned = _tbl.Table.Clone(); dtCloned.Columns[0].DataType = typeof(Int32); foreach (CheckedListBoxItem v in clbColumns.CheckedItems) { string[] zzz = Convert.ToString(v.Value).Split(','); int ind = Convert.ToInt32(zzz[0]); if (_tbl.Table.Columns.GetType() == tp) { /* same type */ } else { dtCloned.Columns[ind].DataType = tp; } //_tbl.Table.Columns.RemoveAt(ind); // v // Columnindex = 0; } foreach (DataRow row in _tbl.Table.Rows) { dtCloned.ImportRow(row); } _tbl.Table = dtCloned; PopulateColumns(); }
private void copyRowToolStripMenuItem_Click(object sender, EventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; var tbl = StaticReference.GetTableByFullName(fileName); GridView view = GetViewFromSelectedTabPage(); if (view == null || tbl == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst")); return; } // MessageBox.Show("ctrlc"); if (view.SelectedRowsCount == 0) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoRowsSelected")); return; } List <DataRow> drList = new List <DataRow>(); for (int i = 0; i < view.SelectedRowsCount; i++) { drList.Add(tbl.Table.Rows[view.GetSelectedRows()[i]]); //view.GetSelectedRows().cl } /* Copy the content of selected rows to the internal clipboard. */ InternalClipboard.Copy(ref drList); view.ClearSelection(); StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_NRowsCopied"), InternalClipboard.GetSize())); }
private void ngEdit_NewColumn_LinkPressed(object sender, NavBarLinkEventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; using (frmColumnEditor columnEditor = new frmColumnEditor(fileName)) { columnEditor.ShowDialog(); } var grid = GetTabPageGrid(fileName); var newTable = StaticReference.GetTableByFullName(fileName); // TODO : Refresh datagrid /* grid.DataSource = null; * grid.DataSource = newTable; * grid.ResetBindings(); * grid.RefreshDataSource();*/ // GetViewFromSelectedTabPage().SynchronizeData(); }
private void simpleButton1_Click(object sender, System.EventArgs e) { if (clbColumns.CheckedItems.Count == 0) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoCheckedItems")); return; } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = LanguageManager.Get("frmExportAsSQL_Filter"); if (sfd.ShowDialog() == DialogResult.OK) { /* Let's begin */ StringBuilder insertQuery = new StringBuilder(); StringBuilder createQuery = new StringBuilder(); int batch = 0; if (ceDropTable.Checked) { createQuery.Append($"DROP TABLE {teTableName.Text};\n"); } createQuery.Append($"CREATE TABLE {teTableName.Text}("); if (ceTruncateTable.Checked) { insertQuery.Append($"TRUNCATE TABLE {teTableName.Text};\n"); } insertQuery.Append($"INSERT INTO {teTableName.Text} VALUES \n"); foreach (CheckedListBoxItem clbi in clbColumns.CheckedItems) { string[] zzz = Convert.ToString(clbi.Value).Split(','); int ind = Convert.ToInt32(zzz[0]); TextEdit te = _columnNames[ind]; createQuery.Append(te.Text); switch (_tbl.Table.Columns[ind].DataType.FullName) { case "System.UInt64": case "System.Int64": createQuery.Append($" bigint,\n"); break; case "System.Double": case "System.Single": createQuery.Append($" real,\n"); break; case "System.UInt32": case "System.Int32": createQuery.Append($" int,\n"); break; case "System.UInt16": case "System.Int16": createQuery.Append($" smallint,\n"); break; case "System.SByte": case "System.Byte": createQuery.Append($" tinyint,\n"); break; case "System.String": createQuery.Append($" varchar(MAX),\n"); break; default: createQuery.Append($" unknown(MAX),\n"); break; } /* EOF cell type switch */ } int insertedRows = 0; foreach (DataRow v in _tbl.Table.Rows) { insertQuery.Append("("); foreach (CheckedListBoxItem clbi in clbColumns.CheckedItems) { string[] zzz = Convert.ToString(clbi.Value).Split(','); int ind = Convert.ToInt32(zzz[0]); DataColumn clmn = _tbl.Table.Columns[ind]; if (clmn.DataType.FullName == "System.String") { insertQuery.Append(("'" + v[clmn].ToString().Replace('\'', '’').Replace("\\", "\\\\") + "',")); } else if (clmn.DataType.FullName == "System.Single" || clmn.DataType.FullName == "System.Double") { /* Convert float notation from ',' to '.' */ insertQuery.Append(Convert.ToString(Convert.ToDouble(v[clmn].ToString())).Replace(",", ".") + ","); } else { insertQuery.Append(v[clmn] + ","); } } insertQuery.Remove(insertQuery.Length - 1, 1); insertQuery.Append("),\n"); if (++insertedRows == 999) { /* We need to break it to several parts. */ insertQuery.Remove(insertQuery.Length - 2, 2); insertQuery.Append(";"); File.WriteAllText(sfd.FileName.Replace(".sql", "") + "_data" + (batch++) + ".sql", insertQuery.ToString()); insertQuery.Clear(); /* prepare for next batch */ insertQuery.Append($"INSERT INTO {teTableName.Text} VALUES \n"); insertedRows = 0; } } insertQuery.Remove(insertQuery.Length - 2, 2); insertQuery.Append(";"); createQuery.Remove(createQuery.Length - 2, 2); createQuery.Append(");\n\n"); if (ceCreateTable.Checked) { File.WriteAllText(sfd.FileName.Replace(".sql", "") + "_ddl" + ".sql", createQuery.ToString()); } File.AppendAllText(sfd.FileName.Replace(".sql", "") + "_data" + (batch++) + ".sql", insertQuery.ToString()); } } StaticReference.ShowInformation(this, LanguageManager.Get("Message_ExportComplete")); }
private void OpenFile(object ofileName) { string fileName = ofileName as string; var fi = new FileInfo(fileName); if (!fi.Exists) { ; StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_FileOpenError"), fileName)); return; } if (StaticReference.GetTableByFullName(fi.FullName) != null) { this.Invoke(new Action(() => { SwitchToTabpage(fi.FullName); })); return; } DataTable table = null; KOEncryptionBase encryption = null; /* Try to decrypt file. */ foreach (var encryptionMethod in StaticReference.EncryptionMethods) { table = encryptionMethod.GetDataTableFromFile(fileName, fi.Name); if (table == null) { continue; } encryption = encryptionMethod; break; } if (table == null) { this.Invoke(new Action(() => { StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_FileEncryptionError"), fi.Name)); return; })); return; } var newTable = new KOTableFile(fi, table, encryption); /* Otherwise, we've succeeded to open file */ StaticReference.AddNewTable(newTable); this.Invoke(new Action(() => { CreateNewTabPage(newTable.Name, newTable.FullName); var grid = GetTabPageGrid(newTable.FullName); grid.KeyPress += Grid_KeyPress; grid.MouseClick += Grid_MouseClick; Trace.Assert(grid != null, "OpenFile() - Grid is null!"); grid.BeginUpdate(); grid.DataSource = table; var view = grid.MainView as GridView; Trace.Assert(view != null, "OpenFile() - GridView is null!"); view.Tag = newTable.FullName; foreach (var v in _itemTableHeaders.Where(v => newTable.Name.ToLowerInvariant().Contains(v.Key))) { view.ColumnPanelRowHeight += 20; for (var i = 0; i < view.Columns.Count; i++) { if (i < v.Value.Length) { view.Columns[i].Caption = string.Format("{0}\n{1}\n{2}", v.Value[i], i, ColumnTypes.GetColumnTypeNameFromFullName(view.Columns[i].ColumnType.FullName)); } } } //view. foreach (GridColumn col in view.Columns) { col.AppearanceCell.Options.UseTextOptions = true; col.AppearanceHeader.Options.UseTextOptions = true; col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; col.AppearanceCell.TextOptions.VAlignment = VertAlignment.Center; col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; col.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center; col.MinWidth = col.ColumnType != typeof(string) ? 150 : 200; col.OptionsColumn.FixedWidth = true; } grid.Refresh(); grid.EndUpdate(); })); }
private void pasteRowToolStripMenuItem_Click(object sender, EventArgs e) { if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; KOTableFile tbl = StaticReference.GetTableByFullName(fileName); GridView view = GetViewFromSelectedTabPage(); if (null == tbl || null == view) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_PasteError")); return; } if (InternalClipboard.DataExists()) { /* * Let's check if copied datarow matches the column length of current table * */ int successfulRows = 0; foreach (var copiedRow in InternalClipboard.GetNext()) { /* * 1. Column count of both tables should be same * 2. Data types of columns for both tables should match */ bool column_ok = true; DataRow newRow = tbl.Table.NewRow(); if (tbl.Table.Columns.Count == copiedRow.Table.Columns.Count) { foreach (DataColumn cColumn in copiedRow.Table.Columns) { if (tbl.Table.Columns[cColumn.Ordinal].DataType != cColumn.DataType) { column_ok = false; break; } else { newRow[cColumn.Ordinal] = copiedRow[cColumn]; } } } else { column_ok = false; } if (column_ok) { successfulRows++; /* Create a new row in table */ /* Insert the row.*/ tbl.Table.Rows.Add(newRow); AddNewRowHighlight(view, newRow); } } /* Scroll to bottom */ view.FocusedRowHandle = view.RowCount - 1; view.TopRowIndex = view.RowCount - 1; if (successfulRows == InternalClipboard.GetSize()) { StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_NRowsAddSuccess"), successfulRows)); } else { StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_CopyError"), successfulRows, InternalClipboard.GetSize())); } } else { StaticReference.ShowWarning(this, LanguageManager.Get("Message_PasteNoRows")); } }
private void TabContextMenuClick(object sender, EventArgs e) { ToolStripMenuItem tsmi = sender as ToolStripMenuItem; if (null == tsmi) { return; } if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null) { StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen")); return; } string fileName = tcMain.SelectedTabPage.Tag as string; switch (tsmi.Name) { case "tpcmSave": { SaveFile(fileName); } break; case "tpcmSaveAs": using (frmSaveAs encSelect = new frmSaveAs(fileName)) { encSelect.ShowDialog(); } break; case "tpcmClose": { if (CloseFile(fileName)) { var q = tcMain.SelectedTabPage; tcMain.TabPages.Remove(q); /* */ q.Dispose(); //.Dispose(); } } break; case "tpcmCloseAllButThis": CloseAll(fileName, CloseAllType.CloseAllButThis); break; case "tpcmCloseAllToLeft": CloseAll(fileName, CloseAllType.CloseAllLeft); break; case "tpcmCloseAllToRight": CloseAll(fileName, CloseAllType.CloseAllRight); break; case "tpcmCloseAll": CloseAll(fileName, CloseAllType.CloseAll); break; case "tpcmOpenFolder": { FileInfo fi = new FileInfo(fileName); { if (fi.Exists) { Process.Start("explorer.exe", fi.Directory.FullName); } } } break; } }