Exemple #1
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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 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);
        }