Esempio n. 1
0
 private void AnalyzeSearchCondition(List <LibSearchCondition> conds, StringBuilder whereformat, ref object[] values)
 {
     SearchConditionHelper.AnalyzeSearchCondition(conds, whereformat, ref values);
     //int n = 0;
     //LibSearchCondition precond=null;
     //int len = 0;
     //foreach (LibSearchCondition item in conds)
     //{
     //    if (whereformat.Length > 0)
     //    {
     //        if (precond != null)
     //            whereformat.AppendFormat(" {0} ", precond.Logic.ToString());
     //    }
     //    switch (item.Symbol)
     //    {
     //        case SmodalSymbol.Equal:
     //            whereformat.Append("" + item.FieldNm + "={" + n + "}");
     //            len = 1;
     //            break;
     //        case SmodalSymbol.MoreThan:
     //            whereformat.Append("" + item.FieldNm + ">{" + n + "}");
     //            len = 1;
     //            break;
     //        case SmodalSymbol.LessThan:
     //            whereformat.Append("" + item.FieldNm + "<{" + n + "}");
     //            len = 1;
     //            break;
     //        case SmodalSymbol.Contains:
     //            whereformat.Append("" + item.FieldNm + " like {" + n + "}");
     //            item.Values[0] = string.Format("%{0}%", item.Values[0]);
     //            len = 1;
     //            break;
     //        case SmodalSymbol.Between:
     //            whereformat.Append("" + item.FieldNm + " between {" + n + "} and {" +(n=n+1) + "}");
     //            len = 2;
     //            break;
     //        case SmodalSymbol.NoEqual:
     //            whereformat.Append("" + item.FieldNm + "!={" + n + "}");
     //            len = 1;
     //            break;
     //    }
     //    n++;
     //    if (item.Values != null)
     //    {
     //        for(int i=0;i<len;i++)
     //        {
     //            //if (LibSysUtils.IsNULLOrEmpty(o)) continue;
     //            Array.Resize(ref values, values.Length + 1);
     //            values[values.Length - 1] =item .Values[i];
     //        }
     //    }
     //    precond = item;
     //}
 }
Esempio n. 2
0
        public override string GenWinFormCS(BasicParameter parameter,
                                            BaseParameter baseParameter)
        {
            NestQueryParameter nestQuerySetting = baseParameter as NestQueryParameter;
            string             strFrmClassName  = nestQuerySetting.FormClassName;
            string             strModelName     = parameter.TableName;
            StringBuilder      sb = new StringBuilder();

            sb.AppendLine("/// <summary>说明:" + strFrmClassName + "文件");
            sb.AppendLine("/// 作者:" + parameter.Author + "");
            sb.AppendLine("/// 创建时间:" + DateTime.Now + "");
            sb.AppendLine("/// </summary>");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Drawing;");
            sb.AppendLine("using System.Diagnostics;");
            sb.AppendLine("using System.Threading.Tasks;");
            sb.AppendLine("using System.Data;");
            sb.AppendLine("using System.Xml.Linq;");
            sb.AppendLine("using Microsoft.VisualBasic;");
            sb.AppendLine("using System.Collections;");
            sb.AppendLine("using System.Windows.Forms;");
            sb.AppendLine("using Nikita.WinForm.ExtendControl;");
            sb.AppendLine("using System.Reflection;");
            sb.AppendLine("using Nikita.Core;");
            sb.AppendLine("using Nikita.Core.WinForm;");
            sb.AppendLine("using Nikita.Core.NPOIs;");
            sb.AppendLine("using Nikita.Core.Images;");
            sb.AppendLine("using Nikita.Core.Autofac;");
            sb.AppendLine("using Nikita.Core.XML;");
            sb.AppendLine("using Nikita.DataAccess4DBHelper;");
            sb.AppendLine("using Nikita.Base.Define;");
            sb.AppendLine("using WeifenLuo.WinFormsUI.Docking;");

            sb.AppendLine("namespace " + parameter.NameSpace + "");
            sb.AppendLine("{");
            sb.AppendLine("    public partial class " + strFrmClassName + "");
            sb.AppendLine("    {");
            #region   变量、常量
            sb.AppendLine("        #region 变量、常量");
            sb.AppendLine("        /// <summary>显示控件");
            sb.AppendLine("        /// ");
            sb.AppendLine("        /// </summary> ");
            sb.AppendLine("        MasterControl _masterDetail;");
            sb.AppendLine("        #endregion");
            #endregion
            #region 构造函数
            sb.AppendLine("        #region 构造函数");
            sb.AppendLine("        public " + strFrmClassName + "()");
            sb.AppendLine("        {");
            sb.AppendLine("            InitializeComponent();");
            sb.AppendLine("        }");
            sb.AppendLine("        #endregion");
            #endregion
            #region 基本事件
            sb.AppendLine("        #region 基本事件");
            sb.AppendLine("        public void btnLoad_Click(object sender, EventArgs e)");
            sb.AppendLine("        {");
            sb.AppendLine("            try");
            sb.AppendLine("            {");
            sb.AppendLine("                btnLoad.Enabled = false;");
            sb.AppendLine("                 LoadData();");
            sb.AppendLine("            }");
            sb.AppendLine("            catch (Exception ex)");
            sb.AppendLine("            {");
            sb.AppendLine("                throw ex;");
            sb.AppendLine("            }");
            sb.AppendLine("            finally");
            sb.AppendLine("            { ");
            sb.AppendLine("                btnLoad.Enabled = true;");
            sb.AppendLine("            }");
            sb.AppendLine("        }");
            sb.AppendLine("        #endregion");
            #endregion
            #region 基本方法
            sb.AppendLine("        #region 基本方法");

            sb.AppendLine("        /// <summary>加载数据");
            sb.AppendLine("        /// ");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public void LoadData()");
            sb.AppendLine("        {");
            sb.AppendLine("            Clear();");
            sb.AppendLine("            CreateMasterDetailView();");
            sb.AppendLine("        }");

            sb.AppendLine("        /// <summary>清空");
            sb.AppendLine("        /// ");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public void Clear()");
            sb.AppendLine("        {");
            sb.AppendLine("            panelView.Controls.Clear();");
            sb.AppendLine("            _masterDetail = null;");
            sb.AppendLine("            Refresh();");
            sb.AppendLine("        }");

            sb.AppendLine("        /// <summary>创建主从关系");
            sb.AppendLine("        /// ");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public void CreateMasterDetailView()");
            sb.AppendLine("        {");
            sb.AppendLine("            var oDataSet = GetData();");
            sb.AppendLine("            _masterDetail = new MasterControl(oDataSet, ControlType.Middle);");
            sb.AppendLine("            panelView.Controls.Add(_masterDetail);");
            sb.AppendLine("        }");

            sb.AppendLine("        /// <summary> 获取数据源");
            sb.AppendLine("        /// ");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <returns>DataSet</returns>");
            sb.AppendLine("        public DataSet GetData()");
            sb.AppendLine("        {");
            sb.AppendLine("            IDbHelper dbHelper = GlobalHelpDemoForm.GetDataAccessHelperDemo();");
            sb.AppendLine("            string strWhere = GetSearchSql();");
            sb.AppendLine("            string strSql =" + nestQuerySetting.Sql + " ");
            sb.AppendLine(";");
            sb.AppendLine("            dbHelper.CreateCommand(strSql);");
            sb.AppendLine("            DataSet dataSet = dbHelper.ExecuteQueryDataSet();");
            if (nestQuerySetting.Key3 != string.Empty)
            {
                sb.AppendLine("         string[] strKeyArray = {\"" + nestQuerySetting.Key1 + "\",\"" + nestQuerySetting.Key2 + "\", \"" + nestQuerySetting.Key3 + "\"};");
            }
            else
            {
                sb.AppendLine("         string[] strKeyArray = {\"" + nestQuerySetting.Key1 + "\",\"" + nestQuerySetting.Key2 + "\" };");
            }
            sb.AppendLine("            for (int i = 0; i < dataSet.Tables.Count; i++)");
            sb.AppendLine("            {");
            sb.AppendLine(" dataSet.Tables[i].TableName = \"T\" + (i + 1);");
            sb.AppendLine("                HashSet<string> hsSet = new HashSet<string>();");
            sb.AppendLine("                foreach (DataRow drRow in dataSet.Tables[i].Rows)");
            sb.AppendLine("                {");
            sb.AppendLine("                    string strKey = strKeyArray[i];");
            sb.AppendLine("                    string strValue = drRow[strKey].ToString();");
            sb.AppendLine("                    if (!hsSet.Contains(strValue))");
            sb.AppendLine("                    {");
            sb.AppendLine("                        hsSet.Add(strValue);");
            sb.AppendLine("                    }");
            sb.AppendLine("                }");
            sb.AppendLine("                if (i < dataSet.Tables.Count - 1)");
            sb.AppendLine("                {");
            sb.AppendLine("                    for (int j = 0; j < dataSet.Tables[i + 1].Rows.Count; j++)");
            sb.AppendLine("                    {");
            sb.AppendLine("                        string strKey2 = strKeyArray[i + 1];");
            sb.AppendLine("                        string strValue2 = dataSet.Tables[i + 1].Rows[j][strKey2].ToString();");
            sb.AppendLine("                        if (!hsSet.Contains(strValue2))");
            sb.AppendLine("                        {");
            sb.AppendLine("                            dataSet.Tables[i + 1].Rows.RemoveAt(j);");
            sb.AppendLine("                            j--;");
            sb.AppendLine("                        }");
            sb.AppendLine("                    }");
            sb.AppendLine("            }");
            sb.AppendLine("     }");
            sb.AppendLine("            //这是对应关系的时候主键必须唯一");
            if (nestQuerySetting.Key3 != string.Empty)
            {
                sb.AppendLine("            dataSet.Relations.Add(\"1\", dataSet.Tables[\"T1\"].Columns[\"" + nestQuerySetting.Key1 + "\"], dataSet.Tables[\"T2\"].Columns[\"" + nestQuerySetting.Key2 + "\"]);");
                sb.AppendLine("             dataSet.Relations.Add(\"2\", dataSet.Tables[\"T2\"].Columns[\"" + nestQuerySetting.Key2 + "\"], dataSet.Tables[\"T3\"].Columns[\"" + nestQuerySetting.Key3 + "\"]);");
            }
            else
            {
                sb.AppendLine("            dataSet.Relations.Add(\"1\", dataSet.Tables[\"T1\"].Columns[\"" + nestQuerySetting.Key1 + "\"], dataSet.Tables[\"T2\"].Columns[\"" + nestQuerySetting.Key2 + "\"]);");
            }
            sb.AppendLine("            return dataSet;");
            sb.AppendLine("        }");

            sb.AppendLine("        /// <summary>根据查询条件构造查询语句");
            sb.AppendLine("        ///");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <returns>查询条件</returns>");
            sb.AppendLine("        private string GetSearchSql()");
            sb.AppendLine("        {");
            sb.AppendLine(SearchConditionHelper.GetSearchCondition(nestQuerySetting.DataTableQuery));
            //sb.AppendLine("            SearchCondition condition = new SearchCondition();");
            //sb.AppendLine("            condition.AddCondition("UserName", this.txtDepartmentName.Text, SqlOperator.Like);");
            //sb.AppendLine("            return condition.BuildConditionSql().Replace("Where", "");");
            sb.AppendLine("        }");
            sb.AppendLine("        #endregion");
            #endregion
            sb.AppendLine("    }");
            sb.AppendLine("}");

            return(sb.ToString());
        }