コード例 #1
0
        private DataTable _GetMainTableStruct <T>(string TableName, int PageSelectIndex, bool SelectSelectDefault)
        {
            DataTable dataTable = new DataTable();

            try
            {
                if (TableName != null)
                {
                    dataTable = _GetTableStruct(TableName);

                    Class_SelectAllModel mySelect = new Class_SelectAllModel();
                    switch (OperateType)
                    {
                    case "select":
                        mySelect = this.class_AllModel as Class_SelectAllModel;
                        #region 加入自定义Select列
                        DataColumn SelectSelect = new DataColumn("SelectSelect", typeof(bool));
                        DataColumn ParaName     = new DataColumn("ParaName", typeof(string));
                        DataColumn MaxLegth     = new DataColumn("MaxLegth", typeof(Int32));
                        DataColumn CaseWhen     = new DataColumn("CaseWhen", typeof(string));
                        DataColumn ReturnType   = new DataColumn("ReturnType", typeof(string));
                        DataColumn TrimSign     = new DataColumn("TrimSign", typeof(bool));
                        DataColumn FunctionName = new DataColumn("FunctionName", typeof(string));

                        DataColumn WhereSelect = new DataColumn("WhereSelect", typeof(bool));
                        DataColumn WhereType   = new DataColumn("WhereType", typeof(string));
                        DataColumn LogType     = new DataColumn("LogType", typeof(string));
                        DataColumn WhereValue  = new DataColumn("WhereValue", typeof(string));
                        DataColumn WhereTrim   = new DataColumn("WhereTrim", typeof(bool));
                        DataColumn WhereIsNull = new DataColumn("WhereIsNull", typeof(bool));

                        DataColumn OrderSelect = new DataColumn("OrderSelect", typeof(bool));
                        DataColumn SortType    = new DataColumn("SortType", typeof(string));
                        DataColumn SortNo      = new DataColumn("SortNo", typeof(Int32));

                        DataColumn GroupSelect = new DataColumn("GroupSelect", typeof(bool));

                        DataColumn HavingSelect    = new DataColumn("HavingSelect", typeof(bool));
                        DataColumn HavingFunction  = new DataColumn("HavingFunction", typeof(string));
                        DataColumn HavingCondition = new DataColumn("HavingCondition", typeof(string));
                        DataColumn HavingValue     = new DataColumn("HavingValue", typeof(string));

                        SelectSelect.DefaultValue = true;
                        TrimSign.DefaultValue     = true;
                        WhereSelect.DefaultValue  = false;
                        WhereTrim.DefaultValue    = true;
                        WhereIsNull.DefaultValue  = true;
                        OrderSelect.DefaultValue  = false;
                        GroupSelect.DefaultValue  = false;
                        HavingSelect.DefaultValue = false;

                        dataTable.Columns.Add(SelectSelect);
                        dataTable.Columns.Add(ParaName);
                        dataTable.Columns.Add(MaxLegth);
                        dataTable.Columns.Add(CaseWhen);
                        dataTable.Columns.Add(ReturnType);
                        dataTable.Columns.Add(TrimSign);
                        dataTable.Columns.Add(FunctionName);

                        dataTable.Columns.Add(WhereSelect);
                        dataTable.Columns.Add(WhereType);
                        dataTable.Columns.Add(LogType);
                        dataTable.Columns.Add(WhereValue);
                        dataTable.Columns.Add(WhereTrim);
                        dataTable.Columns.Add(WhereIsNull);

                        dataTable.Columns.Add(OrderSelect);
                        dataTable.Columns.Add(SortType);
                        dataTable.Columns.Add(SortNo);

                        dataTable.Columns.Add(GroupSelect);

                        dataTable.Columns.Add(HavingSelect);
                        dataTable.Columns.Add(HavingFunction);
                        dataTable.Columns.Add(HavingCondition);
                        dataTable.Columns.Add(HavingValue);
                        #endregion
                        break;

                    case "insert":
                        //mySelect = this.class_AllModel as Class_SelectAllModel;
                        break;

                    case "update":
                        //mySelect = this.class_AllModel as Class_SelectAllModel;
                        break;

                    case "delete":
                        //mySelect = this.class_AllModel as Class_SelectAllModel;
                        break;

                    default:
                        break;
                    }
                    int       Counter     = 1;
                    Class_Sub class_Mains = new Class_Sub();
                    class_Mains = mySelect.class_SubList[PageSelectIndex];
                    foreach (DataRow row in dataTable.Rows)
                    {
                        string myFieldName = row["FieldName"].ToString();
                        bool   IsDefault   = true;
                        row.BeginEdit();
                        if (class_AllModel != null)
                        {
                            switch (OperateType)
                            {
                            case "select":
                            {
                                if (mySelect.class_SubList[PageSelectIndex].class_Fields.Count > 0)
                                {
                                    int FindIndex = class_Mains.class_Fields.FindIndex(a => a.FieldName.Equals(myFieldName));
                                    if (FindIndex > -1)
                                    {
                                        row["SelectSelect"]    = class_Mains.class_Fields[FindIndex].SelectSelect;
                                        row["ParaName"]        = class_Mains.class_Fields[FindIndex].ParaName == null ? row["FieldName"] : class_Mains.class_Fields[FindIndex].ParaName;
                                        row["MaxLegth"]        = class_Mains.class_Fields[FindIndex].MaxLegth;
                                        row["CaseWhen"]        = class_Mains.class_Fields[FindIndex].CaseWhen;
                                        row["ReturnType"]      = class_Mains.class_Fields[FindIndex].ReturnType;
                                        row["TrimSign"]        = class_Mains.class_Fields[FindIndex].TrimSign;
                                        row["FunctionName"]    = class_Mains.class_Fields[FindIndex].FunctionName;
                                        row["WhereSelect"]     = class_Mains.class_Fields[FindIndex].WhereSelect;
                                        row["WhereType"]       = class_Mains.class_Fields[FindIndex].WhereType;
                                        row["LogType"]         = class_Mains.class_Fields[FindIndex].LogType;
                                        row["WhereValue"]      = class_Mains.class_Fields[FindIndex].WhereValue;
                                        row["WhereTrim"]       = class_Mains.class_Fields[FindIndex].WhereTrim;
                                        row["WhereIsNull"]     = class_Mains.class_Fields[FindIndex].WhereIsNull;
                                        row["OrderSelect"]     = class_Mains.class_Fields[FindIndex].OrderSelect;
                                        row["SortType"]        = class_Mains.class_Fields[FindIndex].SortType;
                                        row["SortNo"]          = class_Mains.class_Fields[FindIndex].SortNo;
                                        row["GroupSelect"]     = class_Mains.class_Fields[FindIndex].GroupSelect;
                                        row["HavingSelect"]    = class_Mains.class_Fields[FindIndex].HavingSelect;
                                        row["HavingFunction"]  = class_Mains.class_Fields[FindIndex].HavingFunction;
                                        row["HavingCondition"] = class_Mains.class_Fields[FindIndex].HavingCondition;
                                        row["HavingValue"]     = class_Mains.class_Fields[FindIndex].HavingValue;
                                        IsDefault = false;
                                    }
                                }
                                if (IsDefault)
                                {
                                    row["SortType"]   = "升序";
                                    row["LogType"]    = "=";
                                    row["WhereType"]  = "AND";
                                    row["WhereValue"] = "参数";
                                    row["ParaName"]   = Class_Tool.GetFirstCodeLow(row["FieldName"].ToString());
                                    row["MaxLegth"]   = row["FieldLength"];
                                    row["ReturnType"] = row["FieldType"];
                                    row["SortNo"]     = Counter++;
                                }
                            }
                            break;

                            case "insert":
                                break;

                            case "update":
                                break;

                            case "delete":
                                break;

                            default:
                                break;
                            }
                        }
                        row.EndEdit();
                    }
                    if (dataTable.GetChanges() != null)
                    {
                        dataTable.AcceptChanges();
                    }
                    return(dataTable);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                dataTable.Dispose();
            }
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: 406544970/MDIDemo
        public void OpenSelectWin(string xmlFileName)
        {
            IClass_InterFaceDataBase class_InterFaceDataBase;
            Class_PublicMethod       class_PublicMethod   = new Class_PublicMethod();
            Class_SelectAllModel     class_SelectAllModel = new Class_SelectAllModel();

            Class_SelectAllModel.Class_SelectDataBase class_SelectDataBase = new Class_SelectAllModel.Class_SelectDataBase();
            try
            {
                Class_WindowType class_WindowType = new Class_WindowType();
                class_WindowType.WindowType = "select";
                Form_Select form;
                if (xmlFileName != null)
                {
                    if (File.Exists(string.Format("{0}\\select\\{1}.xml", Application.StartupPath, xmlFileName)))
                    {
                        class_SelectAllModel = class_PublicMethod.FromXmlToSelectObject <Class_SelectAllModel>(xmlFileName);
                        class_SelectDataBase = class_SelectAllModel.class_SelectDataBase;
                        switch (class_SelectDataBase.databaseType)
                        {
                        case "MySql":
                            class_InterFaceDataBase = new Class_MySqlDataBase(class_SelectDataBase.dataSourceUrl, class_SelectDataBase.dataBaseName, class_SelectDataBase.dataSourceUserName, class_SelectDataBase.dataSourcePassWord, class_SelectDataBase.Port);
                            break;

                        case "SqlServer 2017":
                            class_InterFaceDataBase = new Class_SqlServer2017DataBase(class_SelectDataBase.dataSourceUrl, class_SelectDataBase.dataBaseName, class_SelectDataBase.dataSourceUserName, class_SelectDataBase.dataSourcePassWord);
                            break;

                        default:
                            class_InterFaceDataBase = new Class_MySqlDataBase(class_SelectDataBase.dataSourceUrl, class_SelectDataBase.dataBaseName, class_SelectDataBase.dataSourceUserName, class_SelectDataBase.dataSourcePassWord, class_SelectDataBase.Port);
                            break;
                        }
                        class_WindowType.XmlFileName = xmlFileName;
                        form      = new Form_Select(mySkinName, xmlFileName);
                        form.Text = string.Format("SELECT:{0}", xmlFileName);
                        form.Tag  = class_WindowType;
                        OpenSubForm(form);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("文件【{0}.xml】不存在,无法打开界面!", xmlFileName)
                                        , "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    form      = new Form_Select(mySkinName);
                    form.Text = "新SELECT";
                    form.Tag  = class_WindowType;
                    OpenSubForm(form);
                }
            }
            catch (Exception e)
            {
                if (xmlFileName != null)
                {
                    MessageBox.Show(string.Format("数据库[{0}:{3}]:Url[{1}],端口[{2}],连接失败,无法打开该界面!\r\n异常:{4}。"
                                                  , class_SelectDataBase.databaseType
                                                  , class_SelectDataBase.dataSourceUrl
                                                  , class_SelectDataBase.Port
                                                  , class_SelectDataBase.dataBaseName
                                                  , e.Message)
                                    , "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(string.Format("异常:{0}。", e.Message)
                                    , "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }