Пример #1
0
        void SpecialHandleDataSourceProgram()
        {
            ComponentLableAndControl nameOffSql = flowLayout.Controls
                                                  .OfType <ComponentLableAndControl>()
                                                  .Where(x => x.Controls["fsql"] != null)
                                                  .FirstOrDefault();

            Control ctrlSql = nameOffSql.Controls["fsql"];

            ComponentLableAndControl nameOffName = flowLayout.Controls
                                                   .OfType <ComponentLableAndControl>()
                                                   .Where(x => x.Controls["fName"] != null)
                                                   .FirstOrDefault();

            Control ctrlName = nameOffName.Controls["fName"];

            DataTable dtSchema = DBHelper.GetDataReader(ctrlSql.Text)?.GetSchemaTable();

            List <string> listStr = new List <string>(20);

            listStr.Add($@"
if not exists (select 1 from t_interface where finterfacename='{ctrlName.Text}')
begin
insert into t_interface(finterfacename) values('{ctrlName.Text}')
end

");


            foreach (DataRow dr in dtSchema.Rows)
            {
                string sSql = $@"
if not  exists (select 1 from T_InterfaceColums a where a.fInterfacename='{ctrlName.Text}' and a.fColName='{dr["ColumnName"] + ""}')
begin
INSERT INTO T_InterfaceColums (fColName,fInterFaceColIsTree,fInterfacename,fEmpty,fDefaultValue,fKey,fColType,fDataSource,fDataSourceCols,fDataMapCols,fNum,fVisiable)
     VALUES('{dr["ColumnName"] + ""}',0,'{ctrlName.Text}',{((bool)dr["AllowDBNull"] ? 1 : 0)},''
,{(bool.TryParse(dr["IsKey"] + "", out bool bres) ? bres ? 1 : 0 : 0)},'','','','',0,1)
end

";

                listStr.Add(sSql);
            }
            DBHelper.RunSql(listStr, CommandType.Text, null);
        }
Пример #2
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitializeData()
        {
            try
            {
                this.Height = this.PanelBtnOKCancel.Height;

                string[] ParentKeysValues = _mGrid.PrePrimaryKeyValues;
                string[] ChildKeys        = _mGrid.PrimaryKey;


                int itenWidth = 0;

                foreach (DataGridViewColumn col in _mGrid.Columns)
                {
                    ComponentLableAndControl lableAndControl = new ComponentLableAndControl();
                    lableAndControl.SetDisplayName(col.HeaderText);

                    ColumnInfo ColInfo = col.Tag as ColumnInfo;

                    Control ctrl = null;
                    if (col.CellType.Equals(typeof(DataGridViewCheckBoxCell)))
                    {
                        ctrl = new CheckBox()
                        {
                            Name = col.DataPropertyName, Dock = DockStyle.Right
                        };
                    }
                    else
                    {
                        ctrl = new TextBox()
                        {
                            Name = col.DataPropertyName, Dock = DockStyle.Right
                        };
                        ctrl.Text = ColInfo.DefaultValue;
                    }

                    if (_mbEdit)
                    {
                        if (col.CellType.Equals(typeof(DataGridViewCheckBoxCell)))
                        {
                            CheckBox chk = ctrl as CheckBox;
                            chk.Checked = (bool)_mDataRow.Cells[ctrl.Name].Value;
                            chk.Enabled = !ColInfo.ReadOnly;
                        }
                        else
                        {
                            TextBox txt = ctrl as TextBox;
                            txt.Text     = _mDataRow.Cells[ctrl.Name].Value + "";
                            txt.ReadOnly = ColInfo.ReadOnly;
                        }
                    }
                    else
                    {
                        if (ChildKeys != null)
                        {
                            for (int i = 0; i < ChildKeys.Length; i++)
                            {
                                if (ChildKeys[i].Equals(ctrl.Name, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (col.CellType.Equals(typeof(DataGridViewCheckBoxCell)))
                                    {
                                        CheckBox chk = ctrl as CheckBox;
                                        chk.Checked = Convert.ToBoolean(ParentKeysValues[i]);
                                        chk.Enabled = !ColInfo.ReadOnly;
                                    }
                                    else
                                    {
                                        TextBox txt = ctrl as TextBox;
                                        txt.Text     = ParentKeysValues[i];
                                        txt.ReadOnly = ColInfo.ReadOnly;
                                    }
                                }
                            }
                        }
                    }

                    lableAndControl.AddControl(ctrl);

                    lableAndControl.Visible = ColInfo.Visible;

                    flowLayout.Controls.Add(lableAndControl);
                    this.Height += lableAndControl.Height * 2;
                    itenWidth    = lableAndControl.Width;
                }
                this.Width = itenWidth + 50;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
        }