public static string Connect(string InitialConStr = "") { try { var frm = new OracleConnectorDialog(); if (InitialConStr.IsEmpty()) { frm.rdBasic.Checked = true; } else { frm.rdConStr.Checked = true; frm.pnlBasic.Enabled = false; frm.pnlConStr.Enabled = true; frm.tbFullConStr.Text = InitialConStr; } var dlgRes = frm.ShowDialog(); return(frm.SelectedConnectionString); } catch (Exception ex) { ControlMod.PromptMsg(ex); } return(""); }
private void btnConnect_Click(object sender, EventArgs e) { try { if (rdBasic.Checked) { if (tbUsername.Text.NullTrimer().NotEmpty() && tbPassword.Text.NotEmpty() && cmbProtocol.Text.NotEmpty() && tbHost.Text.NotEmpty() && tbPort.Text.NotEmpty() && tbSID.Text.NotEmpty()) { var __conStr = String.Format(@"user id={0};password={1};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL={2}) (HOST={3})(PORT={4})))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={5})))", tbUsername.Text.NullTrimer(), tbPassword.Text, cmbProtocol.Text, tbHost.Text, tbPort.Text, tbSID.Text); this.SelectedConnectionString = __conStr; this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } } else if (tbFullConStr.Text.NotEmpty()) { this.SelectedConnectionString = tbFullConStr.Text; DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } } catch (Exception ex) { ControlMod.PromptMsg(ex); } }
private void DoWait(bool wait) { this.Controls.Add(lblWait); lblWait.BringToFront(); ControlMod.CenterControl(lblWait, true); lblWait.Visible = wait; Application.DoEvents(); }
public void GenerateCSharpClass(CrmEntity crmEntity) { if (string.IsNullOrWhiteSpace(CacheManager.Namespace)) { CacheManager.Namespace = ControlMod.InputBox("", "Please enter a namespace", CacheManager.Namespace); } Manager.GenerateCSharpClass(ClassOptions.FromCrmEntity(crmEntity, CacheManager.Namespace)); }
public static string GetCSharpSelectFunctions(DataTable data, string className, string customClassName) { if (data == null) { return(string.Empty); } var cleanClassName = className.SplitterByUnderscore(); if (customClassName.IsEmpty()) { customClassName = ControlMod.InputBox("", "Class name", cleanClassName); } cleanClassName = customClassName; var __s = @" /// <summary> /// Retrieves " + cleanClassName + @". /// </summary> public " + cleanClassName + @"Collection Get" + (cleanClassName.EndsWith("y") ? cleanClassName.Substring(0, cleanClassName.Length - 1) + "ie" : cleanClassName) + @"s() { return DataOperation(ds => { var results = ds.ExecuteQuery<" + cleanClassName + @">( @""SELECT " + Environment.NewLine; __s += data.Columns.Cast <DataColumn>().Select(o => " " + GetColumnQuerySlice(o) ).Aggregate((f1, f2) => f1 + ", " + Environment.NewLine + f2); __s += Environment.NewLine + @" FROM " + className + @"""); var " + (cleanClassName[0].ToString().ToLower() + cleanClassName.Substring(1)) + @"Collection = new " + cleanClassName + @"Collection(); if (NotEmpty(results)) { " + (cleanClassName[0].ToString().ToLower() + cleanClassName.Substring(1)) + @"Collection.AddRange(results); } return " + (cleanClassName[0].ToString().ToLower() + cleanClassName.Substring(1)) + @"Collection; }); }" + Environment.NewLine + Environment.NewLine; return(__s); }
private void MainForm_Load(object sender, EventArgs e) { try { var lastConStr = ControlMod.GetRegistryValue(ControlMod.cntConStr, "").AsString(); if (lastConStr.NotEmpty()) { OracleHelper.constr = lastConStr; } } catch (Exception ex) { ex.PromptMsg(); } }
public int ExecQuery() { try { if (_disableExec) { return(0); } if (OracleHelper.constr.NotEmpty()) { if (tbScript.Text.NotEmpty()) { _execStarTime = DateTime.Now; var script = tbScript.Text; Async.GetDataAsync <DataTable>(() => { var data = OracleHelper.GetDatatable(script); return(data); }, (DataTable data) => { grd.DataSource = null; grd.DataSource = data; var delta = (DateTime.Now - _execStarTime); if (OnExecutionDone != null) { OnExecutionDone(this, new ExecDoneEventArgs() { ExecTime = delta.TotalMilliseconds }); } }); } } else { ControlMod.PromptMsg("Please connect to an Oracle data first !"); } } catch (Exception ex) { ex.PromptMsg(); } return(grd.RowCount); }
public void ExecuteBulk() { try { if (_disableExec) { return; } if (OracleHelper.constr.NotEmpty()) { if (tbScript.Text.NotEmpty()) { _execStarTime = DateTime.Now; var errorMessage = string.Empty; var success = OracleHelper.ExecuteBulk(tbScript.Text, ref errorMessage); var dt = new DataTable(); dt.Columns.Add(new DataColumn("Result", typeof(string))); var row = dt.NewRow(); row[0] = success ? "Done" : errorMessage; dt.Rows.Add(row); grd.DataSource = null; grd.DataSource = dt; if (OnExecutionDone != null) { OnExecutionDone(this, new ExecDoneEventArgs() { ExecTime = (DateTime.Now - _execStarTime).Milliseconds }); } } } else { ControlMod.PromptMsg("Please connect to an Oracle data first !"); } } catch (Exception ex) { ex.PromptMsg(); } }
private void GenerateCSharpClassesWithCollection() { try { var tb = tab.SelectedTab; if (tb != null && tb.Controls.Count > 0) { DoWait(true); var qrCurrent = tb.Controls.Find("qr", true)[0] as Controls.QueryResultCtl; var items = qrCurrent.GetText().Split(';').Select(o => o.NullTrimer()).ToList(); if (items.NotEmpty()) { if (compName.IsEmpty()) { compName = ControlMod.InputBox("", "Company name"); } if (nameSpace.IsEmpty()) { nameSpace = ControlMod.InputBox("", "Namespace"); } var __s = string.Empty; foreach (var item in items) { var customClassName = ControlMod.InputBox("", "Class name", item); var data = OracleHelper.GetDatatable(String.Format(@"SELECT * FROM {0} WHERE 0=1", item.ToString())); ClassGenerater.GetCSharpClass(data, item, true, true, compName, nameSpace, customClassName); __s += ClassGenerater.GetCSharpSelectFunctions(data, item, customClassName); } qrCurrent.SetText(__s); qrCurrent.HidePanel2(); } } } catch (Exception ex) { ex.PromptMsg(); } DoWait(false); }
public int ExecQueryForDotNetTypes() { try { if (_disableExec) { return(0); } if (OracleHelper.constr.NotEmpty()) { if (tbScript.Text.NotEmpty()) { _execStarTime = DateTime.Now; var data = OracleHelper.GetDatatable(tbScript.Text); grd.DataSource = null; grd.DataSource = data.Columns.Cast <DataColumn>().Select(col => new { ColumnName = col.ColumnName, Type = col.DataType, MaxLength = col.MaxLength }).OrderBy(col => col.ColumnName).ToList(); if (grd.Columns.Count > 0) { grd.Columns[0].Width = 230; } if (OnExecutionDone != null) { OnExecutionDone(this, new ExecDoneEventArgs() { ExecTime = (DateTime.Now - _execStarTime).Milliseconds }); } } } else { ControlMod.PromptMsg("Please connect to an Oracle data first !"); } } catch (Exception ex) { ex.PromptMsg(); } return(grd.ColumnCount); }
public int ExecProc() { try { if (_disableExec) { return(0); } _execStarTime = DateTime.Now; if (OracleHelper.constr.NotEmpty()) { if (tbScript.Text.NotEmpty()) { _lastOutputParam = ControlMod.InputBox("", "Enter output param", _lastOutputParam); var data = OracleHelper.ExecuteFunctionOrProcedure(tbScript.Text, _lastOutputParam); var dt = new DataTable(); dt.Columns.Add(new DataColumn(_lastOutputParam, typeof(string))); var row = dt.NewRow(); row[0] = data; grd.DataSource = null; grd.DataSource = dt; if (OnExecutionDone != null) { OnExecutionDone(this, new ExecDoneEventArgs() { ExecTime = (DateTime.Now - _execStarTime).Milliseconds }); } } } else { ControlMod.PromptMsg("Please connect to an Oracle data first !"); } } catch (Exception ex) { ex.PromptMsg(); } return(grd.RowCount); }
private void GenerateCSharpConstants() { if (lstEntities.SelectedItems.Count > 0) { Wait(); if (string.IsNullOrWhiteSpace(CacheManager.Namespace)) { CacheManager.Namespace = ControlMod.InputBox("", "Please enter a namespace", CacheManager.Namespace); } foreach (object item in lstEntities.SelectedItems) { _crmManager.GenerateCSharpConstants(ClassOptions.FromCrmEntity((CrmEntity)item, CacheManager.Namespace)); } Wait(false); } }
private void btnConnect_Click(object sender, EventArgs e) { try { var sInput = OracleConnectorDialog.Connect(OracleHelper.constr); // ControlMod.InputBox("Enter connection string", "Enter connection string", OracleHelper.constr); if (sInput.NotEmpty()) { DoWait(true); OracleHelper.constr = sInput; using (var con = new OracleConnection(OracleHelper.constr)) { var owners = DBHelper.ExecuteQuery <string>(OracleHelper.owners, con).Select(o => new { id = o }).ToList(); ControlMod.FillCombo(cmbData, owners, "id", "id"); } } } catch (Exception ex) { ex.PromptMsg(); } DoWait(false); }
public static DataTable GetDatatable(OracleConnection _con, string sQuery, params OracleParameter[] OracleParams) { DataTable res = new DataTable(); try { using (var da = new OracleDataAdapter(sQuery, _con)) { if (_con.State != ConnectionState.Open) { _con.Open(); } da.SelectCommand.Parameters.AddRange(OracleParams); da.Fill(res); } } catch (Exception ex) { ControlMod.PromptMsg(ex); } return(res); }
public static object GetScalar(OracleConnection _con, string sQuery, params OracleParameter[] OracleParams) { object res = null; try { using (var cmd = new OracleCommand(sQuery, _con)) { if (_con.State != ConnectionState.Open) { _con.Open(); } cmd.Parameters.AddRange(OracleParams); res = cmd.ExecuteScalar(); } } catch (Exception ex) { ControlMod.PromptMsg(ex); } return(res); }
public static bool ExecCommand(OracleConnection _con, string sQuery, params OracleParameter[] OracleParams) { bool res = false; try { using (var cmd = new OracleCommand(sQuery, _con)) { if (_con.State != ConnectionState.Open) { _con.Open(); } cmd.Parameters.AddRange(OracleParams); cmd.ExecuteNonQuery(); res = true; } } catch (Exception ex) { ControlMod.PromptMsg(ex); } return(res); }
public static string GetCSharpClass(DataTable data, string className, bool withWcfDecorators, bool withCollectionClass, string companyName, string nameSpace, string customClassName) { if (data == null) { return(string.Empty); } var cleanClassName = className.SplitterByUnderscore(); if (customClassName.IsEmpty()) { customClassName = ControlMod.InputBox("", "Class name", cleanClassName); } cleanClassName = customClassName; if (nameSpace.IsEmpty()) { nameSpace = "<ToBeSet>"; } var __s = "//------------------------------------------------------------------" + Environment.NewLine + "// <copyright file=\"" + cleanClassName + ".cs\" company=\"" + companyName + "\">" + Environment.NewLine + "// Copyright (c) " + companyName + " Ltd. All rights reserved." + Environment.NewLine + "// </copyright>" + Environment.NewLine + "//" + Environment.NewLine + "// <summary>" + Environment.NewLine + "// An object that is used to hold the " + cleanClassName + " info." + Environment.NewLine + "// </summary>" + Environment.NewLine + "//" + Environment.NewLine + "// <remarks/>" + Environment.NewLine + "//------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine + "namespace " + nameSpace + Environment.NewLine + "{" + Environment.NewLine + " using System.Runtime.Serialization;" + Environment.NewLine + "" + Environment.NewLine + " /// <summary>" + Environment.NewLine + " /// An object that is used to hold the " + cleanClassName + "." + Environment.NewLine + " /// </summary>" + Environment.NewLine + (withWcfDecorators ? " [DataContract]" + Environment.NewLine : "") + " public class " + cleanClassName + Environment.NewLine + " {" + Environment.NewLine; __s += data.Columns.Cast <DataColumn>().Select(o => Environment.NewLine + " /// <summary>" + Environment.NewLine + " /// Represents the " + o.ColumnName.SplitterByUnderscore() + Environment.NewLine + " /// </summary>" + Environment.NewLine + (withWcfDecorators ? " [DataMember]" + Environment.NewLine : "") + " public " + GetTypeString(o.DataType) + " " + o.ColumnName.SplitterByUnderscore() + " { get; set; }" + Environment.NewLine ).Aggregate((f1, f2) => f1 + f2); __s += Environment.NewLine + " }"; __s += Environment.NewLine + "}"; /*-------------------------------------------------- Collection Class -------------------------------------------------*/ var __sCollection = "//------------------------------------------------------------------" + Environment.NewLine + "// <copyright file=\"" + cleanClassName + "Collection.cs\" company=\"" + companyName + "\">" + Environment.NewLine + "// Copyright (c) " + companyName + " Ltd. All rights reserved." + Environment.NewLine + "// </copyright>" + Environment.NewLine + "//" + Environment.NewLine + "// <summary>" + Environment.NewLine + "// An object that is used to hold the " + cleanClassName + "Collection info." + Environment.NewLine + "// </summary>" + Environment.NewLine + "//" + Environment.NewLine + "// <remarks/>" + Environment.NewLine + "//------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine + "namespace " + nameSpace + Environment.NewLine + "{" + Environment.NewLine + " using System.Collections.Generic;" + Environment.NewLine + " using System.Runtime.Serialization;" + Environment.NewLine + "" + Environment.NewLine + " /// <summary>" + Environment.NewLine + " /// An object that is used to hold the " + cleanClassName + "Collection." + Environment.NewLine + " /// </summary>" + Environment.NewLine + (withWcfDecorators ? " [CollectionDataContract]" + Environment.NewLine : "") + " public class " + cleanClassName + "Collection : List<" + cleanClassName + ">" + Environment.NewLine + " {" + Environment.NewLine; __sCollection += Environment.NewLine + " }"; __sCollection += Environment.NewLine + "}"; System.IO.File.WriteAllText(ControlMod.CombinePath(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), cleanClassName + ".cs"), __s); System.IO.File.WriteAllText(ControlMod.CombinePath(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), cleanClassName + "Collection.cs"), __sCollection); return(__s); }
private void schemaToolStripMenuItem_Click(object sender, EventArgs e) { var newTab = tab.TabPages[tab.TabPages.Count - 1]; FillTab(newTab); tab.SelectedTab = newTab; var qr = newTab.Controls.Find("qr", true)[0] as QueryResultCtl; if (sender.Equals(schemaToolStripMenuItem))//Schema { qr.SetText(@"SELECT column_name, data_type, data_length FROM USER_TAB_COLUMNS WHERE table_name = '" + lstObjects.SelectedItem.ToString() + @"' ORDER BY column_name"); qr.ExecQuery(); } else if (sender.Equals(openWithAllFieldsToolStripMenuItem))// Open with all fields { var fields = OracleHelper.GetDatatable(@"SELECT column_name FROM USER_TAB_COLUMNS WHERE table_name = '" + lstObjects.SelectedItem.ToString() + @"'"); if (fields.NotEmpty()) { var sCols = fields.Rows.Cast <DataRow>().Select(o => o[0]).Aggregate((f1, f2) => f1 + ", " + f2); qr.SetText(String.Format(@"SELECT {0} FROM {1} WHERE ROWNUM <= {2}", sCols, lstObjects.SelectedItem.ToString(), numRowLimit.Text)); qr.ExecQuery(); } } else if (sender.Equals(generateCClassToolStripMenuItem) || sender.Equals(generateCClassWCFToolStripMenuItem))// Generate C# class { var data = OracleHelper.GetDatatable(String.Format(@"SELECT * FROM {0} WHERE 0=1", lstObjects.SelectedItem.ToString())); var __s = ClassGenerater.GetCSharpClass(data, lstObjects.SelectedItem.ToString(), sender.Equals(generateCClassWCFToolStripMenuItem), false, string.Empty, string.Empty, string.Empty); qr.SetText(__s); qr.HidePanel2(); } else if (sender.Equals(generateClassWithCollectionToolStripMenuItem))// Generate C# class { if (lstObjects.SelectedItems.NotEmpty()) { if (compName.IsEmpty()) { compName = ControlMod.InputBox("", "Company name"); } if (nameSpace.IsEmpty()) { nameSpace = ControlMod.InputBox("", "Namespace"); } var __s = string.Empty; foreach (var item in lstObjects.SelectedItems) { var customClassName = ControlMod.InputBox("", "Class name", item.ToString()); var data = OracleHelper.GetDatatable(String.Format(@"SELECT * FROM {0} WHERE 0=1", item.ToString())); ClassGenerater.GetCSharpClass(data, item.ToString(), true, true, compName, nameSpace, customClassName); __s += ClassGenerater.GetCSharpSelectFunctions(data, item.ToString(), customClassName); } qr.SetText(__s); qr.HidePanel2(); } else { GenerateCSharpClassesWithCollection(); } } else if (sender.Equals(generateCSharpQueryfunctionsToolStripMenuItem)) { GenerateCSharpQueryfunctions(); } }
public void ExtractViewsAsTables() { try { if (_disableExec) { return; } if (OracleHelper.constr.NotEmpty()) { var viewsSplittedBySemiColumn = tbScript.Text; StringBuilder sb = new StringBuilder(); var views = viewsSplittedBySemiColumn.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Select(lambView => lambView.NullTrimer()).ToList(); //handles the splitted by comma case if (views.NotEmpty() && views.Count == 1 && viewsSplittedBySemiColumn.Contains(",")) { views = viewsSplittedBySemiColumn.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(lambView => lambView.NullTrimer()).ToList(); } foreach (string view in views) { try { var fields = OracleHelper.GetDatatable(string.Format( @"SELECT table_name view_name, column_name, data_type, nvl(DATA_LENGTH,0) fld_length, NULLABLE FROM all_tab_columns WHERE upper(table_name) = upper('{0}') ORDER BY column_id", view)); if (fields != null && fields.Rows.Count > 0) { sb.AppendLine(@"-------------------------- " + view + " --------------------------"); sb.AppendLine(@"CREATE TABLE apps." + view + " ("); fields.Rows.Cast <DataRow>().ToList().ForEach( row => sb.AppendLine(" " + row["column_name"].ToString() + " " + row["data_type"].ToString() + " " + (int.Parse(row["fld_length"].ToString()) == 0 || row["data_type"].ToString().ToLower() == "date" || row["data_type"].ToString().ToLower() == "blob" ? "" : "(" + row["fld_length"].ToString() + ")") + (row.Equals(fields.Rows[fields.Rows.Count - 1]) ? " " : ", ") + (row["NULLABLE"].ToString().ToUpper() == "Y" ? "-- NULLABLE" : "")) ); sb.AppendLine(@");"); sb.AppendLine(@""); } else { sb.AppendLine("-- " + view + " not found\n\n"); } } catch (Exception ex) { sb.AppendLine("/* Error >> " + ex.Message + "\n" + ex.StackTrace + "*/"); } } System.Windows.Forms.Clipboard.SetText(sb.ToString()); } else { ControlMod.PromptMsg("Please connect to an Oracle data first !"); } } catch (Exception ex) { ex.PromptMsg(); } }
public void ExtractDataAsInsertScript(int rowLimit) { try { if (_disableExec) { return; } if (OracleHelper.constr.NotEmpty()) { var viewsSplittedBySemiColumn = tbScript.Text; StringBuilder sb = new StringBuilder(); var views = //"adasdasd;XXMOB_LEAVE_TYPES_V;XXMOB_LEAVE_APP_HIST_V;XXMOB_CUSTOM_ATTACHMENTS_V;XXMOB_LEAVES_WITH_STATUS_V" //"xxmob_currencies_v;xxmob_emp_po_access_v;xxmob_gl_codes_v;xxmob_po_headers_v;xxmob_po_lines_v;xxenec_ap_payment_terms_v;xxenec_hr_dept_v;xxenec_ou_names_v;xxenec_po_categories_v;xxenec_po_inv_locations_v;xxenec_po_line_types_v;xxmob_po_receipt_lines_v;xxenec_po_pr_req_types_v;xxenec_po_price_types_v;xxenec_po_shipto_loc_v;xxenec_po_types_v;xxenec_po_uom_types_v;xxenec_sup_sites_v;xxenec_suppliers_v;xxmob_purchase_action_hist_v;xxmob_purchase_notfy_v;xxmob_pr_headers_v;xxmob_pr_lines_v;xxmob_po_release_headers_v;xxmob_po_release_lines_v;xxmob_po_receipts_v" viewsSplittedBySemiColumn .Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); foreach (string view in views) { try { var data = OracleHelper.GetDatatable(string.Format( @"SELECT * FROM {0} {1}", view, (rowLimit > 0 ? " WHERE ROWNUM <= " + rowLimit : ""))); if (data != null && data.Rows.Count > 0) { foreach (DataRow row in data.Rows.Cast <DataRow>()) { var fieldNames = "("; var fieldValues = " VALUES ("; foreach (DataColumn column in data.Columns) { if (column.DataType != typeof(byte[])) { var firstCol = fieldNames != "("; fieldNames += (firstCol ? ", " : " ") + column.ColumnName; fieldValues += (firstCol ? ", " : " ") + (column.DataType == typeof(DateTime) && !DBNull.Value.Equals(row[column]) ? "'" + ((DateTime)row[column]).ToString("dd-MMM-yyyy") + "'" : "'" + row[column].ToString().Replace("'", "''").Replace("&", "and") + "'"); } } if (fieldNames != "(") { sb.AppendLine(@"-------------------------- " + view + " --------------------------"); sb.AppendLine(@"INSERT INTO " + view + " "); sb.AppendLine(fieldNames + ")"); sb.AppendLine(fieldValues + ");" + Environment.NewLine); } } } else { sb.AppendLine("-- " + view + " not found\n\n"); } } catch (Exception ex) { sb.AppendLine("/* Error >> " + ex.Message + "\n" + ex.StackTrace + "*/"); } } System.Windows.Forms.Clipboard.SetText(sb.ToString()); } else { ControlMod.PromptMsg("Please connect to an Oracle data first !"); } } catch (Exception ex) { ex.PromptMsg(); } }
private void grd_DataError(object sender, DataGridViewDataErrorEventArgs e) { ControlMod.SaveLog(e.Exception); e.Cancel = true; }
public MainForm() { InitializeComponent(); _crmUrl = ControlMod.GetRegistryValue(ControlMod.cntConStr) as string; }