Ejemplo n.º 1
0
        public void CreateGrid()
        {
            for (int i = 0; i <= this.DataSet.Columns.Count - 1; i++)
            {
                JkDetailColumn column = this.DataSet.Columns[i];

                if (column.DataType == SqlDbType.Bit)
                {
                    CreateColumn(ColumnType.CheckBoxColumn, column, this);
                }
                else if (!String.IsNullOrWhiteSpace(column.ControlName))
                {
                    CreateColumn(ColumnType.ComboBoxColumn, column, this);
                }
                else
                {
                    CreateColumn(ColumnType.TextBoxColumn, column, this);
                }
            }

            foreach (DataGridViewColumn column in this.Columns)
            {
                if (this.DataSet.GridColumn.Find(c => c.Name == column.Name) == null)
                {
                    this.DataSet.GridColumn.Add(column);
                }
            }
        }
Ejemplo n.º 2
0
        public void CreateColumn(ColumnType type, JkDetailColumn column, DataGridView grid)
        {
            if (type == ColumnType.CheckBoxColumn)
            {
                DataGridViewCheckBoxColumn GridColCheck = new DataGridViewCheckBoxColumn();

                GridColCheck.Name             = this.Name + "Column" + column.Name.Trim();
                GridColCheck.HeaderText       = column.Caption;
                GridColCheck.Width            = column.Width;
                GridColCheck.Visible          = column.Visible;
                GridColCheck.DataPropertyName = column.Name;
                GridColCheck.ReadOnly         = column.ReadOnly;

                ApplyColumnStyle(column, GridColCheck);
                grid.Columns.Add(GridColCheck);
            }
            else if (type == ColumnType.ComboBoxColumn)
            {
                DataGridViewComboBoxColumn GridColCombo = new DataGridViewComboBoxColumn();

                GridColCombo.Name             = this.Name + "Column" + column.Name.Trim();
                GridColCombo.HeaderText       = column.Caption;
                GridColCombo.Width            = column.Width;
                GridColCombo.Visible          = column.Visible;
                GridColCombo.DataPropertyName = column.Name;
                GridColCombo.ReadOnly         = column.ReadOnly;
                GridColCombo.AutoComplete     = true;

                ApplyColumnStyle(column, GridColCombo);
                grid.Columns.Add(GridColCombo);
            }
            else if (type == ColumnType.TextBoxColumn)
            {
                DataGridViewTextBoxColumn GridColText = new DataGridViewTextBoxColumn();

                GridColText.Name             = this.Name + "Column" + column.Name.Trim();
                GridColText.HeaderText       = column.Caption;
                GridColText.Width            = column.Width;
                GridColText.Visible          = column.Visible;
                GridColText.DataPropertyName = column.Name;
                GridColText.ReadOnly         = column.ReadOnly;

                ApplyColumnStyle(column, GridColText);
                grid.Columns.Add(GridColText);
            }
        }
Ejemplo n.º 3
0
        public void CreateColumn(ColumnType type, JkDetailColumn column, JkGridColumnSerializer.JkGridColumnProperties properties, DataGridView grid)
        {
            if (type == ColumnType.CheckBoxColumn)
            {
                DataGridViewCheckBoxColumn GridColCheck = new DataGridViewCheckBoxColumn();

                GridColCheck.Name             = properties.Name;
                GridColCheck.HeaderText       = properties.HeaderText;
                GridColCheck.Width            = properties.Width;
                GridColCheck.Visible          = properties.Visible;
                GridColCheck.DataPropertyName = properties.DataPropertyName;
                GridColCheck.ReadOnly         = properties.ReadOnly;

                ApplyColumnStyle(column, GridColCheck);
                grid.Columns.Add(GridColCheck);
            }
            else if (type == ColumnType.ComboBoxColumn)
            {
                DataGridViewComboBoxColumn GridColCombo = new DataGridViewComboBoxColumn();

                GridColCombo.Name             = properties.Name;
                GridColCombo.HeaderText       = properties.HeaderText;
                GridColCombo.Width            = properties.Width;
                GridColCombo.Visible          = properties.Visible;
                GridColCombo.DataPropertyName = properties.DataPropertyName;
                GridColCombo.ReadOnly         = properties.ReadOnly;

                ApplyColumnStyle(column, GridColCombo);
                grid.Columns.Add(GridColCombo);
            }
            else if (type == ColumnType.TextBoxColumn)
            {
                DataGridViewTextBoxColumn GridColText = new DataGridViewTextBoxColumn();

                GridColText.Name             = properties.Name;
                GridColText.HeaderText       = properties.HeaderText;
                GridColText.Width            = properties.Width;
                GridColText.Visible          = properties.Visible;
                GridColText.DataPropertyName = properties.DataPropertyName;
                GridColText.ReadOnly         = properties.ReadOnly;

                ApplyColumnStyle(column, GridColText);
                grid.Columns.Add(GridColText);
            }
        }
Ejemplo n.º 4
0
        private void CreateColumns()
        {
            SqlDataAdapter DataAdapter = new SqlDataAdapter(CommandText, ConnectionString);

            try
            {
                if (Parameters.Count > 0)
                {
                    for (int i = 0; i <= Parameters.Count - 1; i++)
                    {
                        if (String.IsNullOrWhiteSpace(Parameters[i].Value) ||
                            Parameters[i].Value[0].ToString() == "@")
                        {
                            DataAdapter.SelectCommand.Parameters.AddWithValue("@" + Parameters[i].Name, 0);
                        }
                    }
                }
                DataAdapter.Fill(DataTable);

                foreach (DataColumn dc in DataTable.Columns)
                {
                    JkDetailColumn column = new JkDetailColumn();

                    column.Caption  = dc.ColumnName;
                    column.DataType = ConvertTypeToSqlType(dc.DataType);
                    column.Name     = dc.ColumnName;
                    column.Required = !dc.AllowDBNull;
                    if (column.Name.Contains("Id"))
                    {
                        column.Visible = false;
                    }
                    column.Width = 100;

                    if (Columns.Find(col => col.Name == column.Name) == null)
                    {
                        _Columns.Add(column);
                    }
                }
            }
            finally
            {
                DataAdapter.Dispose();
            }
        }
Ejemplo n.º 5
0
 public static void ApplyColumnStyle(JkDetailColumn detailColumn, DataGridViewColumn gridColumn)
 {
     if (detailColumn.DataType == SqlDbType.DateTime) //checkbox
     {
         gridColumn.DefaultCellStyle.Format = "MM'/'dd'/'yyyy";
     }
     else if (!String.IsNullOrWhiteSpace(detailColumn.ControlName)) //combobox
     {
         (gridColumn as DataGridViewComboBoxColumn).DisplayStyle  = DataGridViewComboBoxDisplayStyle.Nothing;
         (gridColumn as DataGridViewComboBoxColumn).DropDownWidth = gridColumn.Width + 50;
     }
     else if (detailColumn.DataType == SqlDbType.Money || //numeric textbox
              detailColumn.DataType == SqlDbType.Float ||
              detailColumn.DataType == SqlDbType.Decimal)
     {
         gridColumn.DefaultCellStyle.Format = "#,##0.00;(#,##0.00)";
         gridColumn.ValueType = Type.GetType("System.Decimal");
         gridColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
     }
 }
Ejemplo n.º 6
0
        public void CreateFooter()
        {
            JkDetailColumn ic = null;
            int            EstimatedWidth = 0, offset = 1, gridWidth = 0;

            if (this.RowHeadersVisible)
            {
                offset = 35;
            }

            if (VisibleColumnCount() != 0)
            {
                EstimatedWidth = Convert.ToInt32((this.Width) / VisibleColumnCount()) - 18;
            }

            GridFooter.Padding = new Padding(3, 3, 3, 3);

            if (DataSet.Columns.Count > 0)
            {
                Label lblOffset = new Label();

                lblOffset.Name   = "lblFooterOffset";
                lblOffset.Width  = offset;
                lblOffset.Margin = new Padding(0, 0, 0, 0);

                if (GridFooter.Controls.Find(lblOffset.Name, false).Length == 0)
                {
                    GridFooter.Controls.Add(lblOffset);
                }

                for (int i = 0; i <= DataSet.Columns.Count - 1; i++)
                {
                    ic = DataSet.Columns[i];

                    foreach (DataGridViewColumn column in this.Columns)
                    {
                        if (column.DataPropertyName == ic.Name)
                        {
                            gridWidth = column.Width;
                        }
                    }

                    if (ic.Visible)
                    {
                        Label lblFooter = new Label();
                        lblFooter.Name      = "lblFooter" + ic.Caption.Trim();
                        lblFooter.TextAlign = ContentAlignment.MiddleCenter;
                        lblFooter.Text      = AssignFooterValue(ic.FooterType, "0");
                        lblFooter.Font      = new Font(this.Font.Name, this.Font.Size - 1, FontStyle.Bold);


                        if (DataSet.GridAutoSize)
                        {
                            lblFooter.Width = EstimatedWidth;
                        }
                        else
                        {
                            lblFooter.Width = gridWidth;
                        }

                        if (ic.FooterType != JkDetailColumn.ColumnFooterTypes.ftNone)
                        {
                            lblFooter.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                            lblFooter.Margin      = new Padding(2, 0, 0, 0);
                        }
                        else
                        {
                            lblFooter.Margin = new Padding(0, 0, 0, 0);
                        }

                        if (GridFooter.Controls.Find(lblFooter.Name, false).Length == 0)
                        {
                            GridFooter.Controls.Add(lblFooter);
                        }
                    }
                }
            }
        }