public void GenDefControl(int dis, ref bool lr, ref int sum, ref int maxwinwidth, ref int maxwinheight, SQLTableInfo item)
        {
            sum++;
            IComponent iclbl = this.AddControl(typeof(Label), "lbl" + BaseGengerator.ClearBadChars(item.t_fieldname));

            (iclbl as Label).Text = ((item.t_fielddesc != null && item.t_fielddesc as string != "") ? item.t_fielddesc : item.t_fieldname) as string;
            IComponent ictxt;
            Type       t = Keel.DB.Common.NowDataBase.PasteType(item.t_fieldtype);

            if (t.Equals(typeof(string)))
            {
                ictxt = this.AddControl(typeof(TextBox), "txt" + BaseGengerator.ClearBadChars(item.t_fieldname));
            }

            else if (t.Equals(typeof(DateTime)))
            {
                ictxt = this.AddControl(typeof(DateTimePicker), "dtp" + BaseGengerator.ClearBadChars(item.t_fieldname));
            }

            else if (t.Equals(typeof(decimal)) || t.Equals(typeof(Int32)) || t.Equals(typeof(float)) || t.Equals(typeof(double)) ||
                     t.Equals(typeof(byte)) || t.Equals(typeof(int)) || t.Equals(typeof(Int16)) || t.Equals(typeof(Int64))
                     )
            {
                ictxt = this.AddControl(typeof(NumericUpDown), "nud" + item.t_fieldname);
            }
            else
            {
                ictxt = this.AddControl(typeof(TextBox), "txt_unsupport_type_" + item.t_fieldname);
            }

            int y;
            int xxx = Math.DivRem(sum, 2, out y) + y;

            // (ictxt as Control).Tag = item.t_fieldname;
            (ictxt as Control).TabIndex = (int)item.t_fieldindex;
            switch (lr)
            {
            default:
            case true:
                (iclbl as Label).Location   = new Point(20 + 300, dis * xxx);
                (ictxt as Control).Location = new Point(20 + 300 + (iclbl as Label).Width + dis, dis * xxx);
                int fw = (ictxt as Control).Left + (ictxt as Control).Width;
                int fh = (ictxt as Control).Top + (ictxt as Control).Height;
                maxwinwidth  = maxwinwidth > fw ? maxwinwidth : fw;
                maxwinheight = maxwinheight > fh ? maxwinheight : fh;
                lr           = false;
                break;

            case false:
                (iclbl as Label).Location   = new Point(20, dis * xxx);
                (ictxt as Control).Location = new Point(20 + (iclbl as Label).Width + dis, dis * xxx);
                lr = true;
                break;
            }
        }
Example #2
0
        public void AddCtor(List <SQLTableInfo> lst, KeelKit.Serialization.KeelExt.ModelKind mk)
        {
            CodeConstructor cc = new CodeConstructor();

            cc.Name       = ctd.Name;
            cc.Attributes = (cc.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            CodeConstructor cc3 = new CodeConstructor();

            cc3.Name       = ctd.Name;
            cc3.Attributes = (cc3.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            foreach (var dbi in lst)
            {
                if (dbi.t_fieldiscomputed != OK && dbi.t_identity != OK)
                {
                    Type t = Keel.DB.Common.NowDataBase.PasteType(dbi.t_fieldtype);
                    CodeParameterDeclarationExpression cpde = new CodeParameterDeclarationExpression(t, "param_" + BaseGengerator.ClearBadChars(dbi.t_fieldname));
                    CodeAssignStatement cas = new CodeAssignStatement(
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), GetNameByFieldName(dbi.t_fieldname))
                        ,
                        new CodeVariableReferenceExpression("param_" + BaseGengerator.ClearBadChars(dbi.t_fieldname)));
                    cc.Parameters.Add(cpde);
                    cc.Statements.Add(cas);

                    if (dbi.t_fieldcannull != OK)
                    {
                        cc3.Parameters.Add(cpde);
                        cc3.Statements.Add(cas);
                    }
                }
            }
            if (mk != KeelExt.ModelKind.DotNetAndC)
            {
                CodeConstructor cc2 = new CodeConstructor();
                cc2.Name = ctd.Name;
                cc2.Comments.Add(new CodeCommentStatement("<summary>\r\n实例化一个\r\n</summary>" + cc2.Name));
                cc2.Attributes = (cc2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
                ctd.Members.Add(cc2);
            }
            if (cc.Parameters.Count > 0)
            {
                cc.Comments.Add(new CodeCommentStatement(string.Format("<summary>\r\n实例化一个{0},并填写所有字段的值\r\n({1}个)\r\n</summary>", cc.Name, cc.Parameters.Count), true));
                ctd.Members.Add(cc);
            }
            //必填参数数量必须大于0并且小于全部参数的数量。
            if (cc3.Parameters.Count > 0 && cc3.Parameters.Count < cc.Parameters.Count)
            {
                cc3.Comments.Add(new CodeCommentStatement(string.Format("<summary>\r\n实例化一个{0},并填写所有必填字段个的值\r\n(共{1})\r\n</summary>", cc3.Name, cc3.Parameters.Count), true));
                ctd.Members.Add(cc3);
            }
        }