コード例 #1
0
        public void updateItemList(CustomCollection collection)
        {
            infoPanel.Hide();
            collectionPanel.Show();
            collectionLabel.Text = collection.aliase;

            selectedCollection = collection;

            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
            dataGridView1.Update();
            dataGridView1.Refresh();

            List <dynamic> itemList = dbc.getDocuments(collection);

            fieldSelectionBox.Items.Clear();

            DataTable dt = new DataTable();

            dt.Columns.Add("_id");

            foreach (Attribute attr in collection.attributes)
            {
                var columnSpec = new DataColumn
                {
                    DataType   = typeof(String),
                    ColumnName = attr.name
                };

                if (attr.type == "date")
                {
                    columnSpec.DataType = typeof(DateTime);
                }

                fieldSelectionBox.Items.Add(attr.name);
                dt.Columns.Add(columnSpec);
            }

            fieldSelectionBox.SelectedItem = collection.attributes[0].name;

            foreach (dynamic item in itemList)
            {
                DataRow row = dt.NewRow();
                row["_id"] = item._id;

                foreach (Attribute attr in collection.attributes)
                {
                    String name = attr.name;

                    if (attr.type == "date")
                    {
                        String dateString = item[name];

                        if (dateString == null)
                        {
                            DateTime date = DateTime.ParseExact("01.01.2000", "d.M.yyyy", CultureInfo.InvariantCulture);
                            row[name] = date;
                        }
                        else
                        {
                            DateTime date = DateTime.ParseExact(dateString, "d.M.yyyy", CultureInfo.InvariantCulture);
                            row[name] = date;
                        }
                    }
                    else
                    {
                        row[name] = item[name];
                    }
                }
                dt.Rows.Add(row);
            }

            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.Columns.Clear();
            dataGridView1.DataSource = dt;

            if (dataGridView1.Columns["_id"] != null)
            {
                dataGridView1.Columns["_id"].Visible = false;
            }
        }
コード例 #2
0
        public EditItem(Main mainForm, CustomCollection customCol, DataGridViewRow selectedRow)
        {
            InitializeComponent();
            dbc = new DatabaseController();

            this.mainForm    = mainForm;
            this.customCol   = customCol;
            this.selectedRow = selectedRow;

            tableLayoutPanel1.Controls.Clear();

            tableLayoutPanel1.ColumnStyles.Clear();
            tableLayoutPanel1.RowStyles.Clear();

            tableLayoutPanel1.ColumnCount = 2;
            tableLayoutPanel1.RowCount    = customCol.attributes.Count;


            tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));

            for (int y = 0; y < customCol.attributes.Count; y++)
            {
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F));

                Label fieldName = new Label();
                fieldName.Text      = customCol.attributes[y].name;
                fieldName.TextAlign = ContentAlignment.MiddleRight;
                fieldName.Anchor    = (AnchorStyles.Left | AnchorStyles.Right);
                tableLayoutPanel1.Controls.Add(fieldName, 0, y);



                if (customCol.attributes[y].type == "text")
                {
                    TextBox fieldTextBox = new TextBox();
                    fieldTextBox.Text   = selectedRow.Cells[customCol.attributes[y].name].Value.ToString();
                    fieldTextBox.Tag    = customCol.attributes[y].name;
                    fieldTextBox.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
                    tableLayoutPanel1.Controls.Add(fieldTextBox, 1, y);
                }
                else if (customCol.attributes[y].type == "number")
                {
                    TextBox fieldTextBox = new TextBox();
                    fieldTextBox.Text   = selectedRow.Cells[customCol.attributes[y].name].Value.ToString();
                    fieldTextBox.Tag    = customCol.attributes[y].name;
                    fieldTextBox.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
                    tableLayoutPanel1.Controls.Add(fieldTextBox, 1, y);
                }
                else if (customCol.attributes[y].type == "date")
                {
                    DateTimePicker fieldDate = new DateTimePicker();

                    fieldDate.Text = selectedRow.Cells[customCol.attributes[y].name].Value.ToString();

                    fieldDate.Tag    = customCol.attributes[y].name;
                    fieldDate.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
                    tableLayoutPanel1.Controls.Add(fieldDate, 1, y);
                }
            }

            tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F));
            tableLayoutPanel1.Controls.Add(new Label(), 0, customCol.attributes.Count);
            tableLayoutPanel1.Controls.Add(new Label(), 1, customCol.attributes.Count);
        }
コード例 #3
0
 public void setSelectedCollection(CustomCollection selectedCollection)
 {
     this.selectedCollection = selectedCollection;
 }