Exemplo n.º 1
0
        private void CartForm_Load(object sender, EventArgs e)
        {
            dgv_Cart.DataSource = Cart.Select(t => new
            {
                Title  = t.Name,
                Artist = t.Album.Artist.Name,
                Price  = t.UnitPrice
            }).ToList();

            var maxWidth = (dgv_Cart.Width / 3) - 25;

            dgv_Cart.AutoSizeRowsMode    = DataGridViewAutoSizeRowsMode.DisplayedCells;
            dgv_Cart.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
            foreach (DataGridViewColumn column in dgv_Cart.Columns)
            {
                if (column.Width > maxWidth)
                {
                    column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                    column.Width        = maxWidth;
                }
            }

            NumericUpDownColumn numericUpDownColumn = new NumericUpDownColumn();

            numericUpDownColumn.HeaderText = "Quantity";
            dgv_Cart.Columns.Insert(3, numericUpDownColumn);

            DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn();

            buttonColumn.HeaderText = "Remove from cart";
            dgv_Cart.Columns.Insert(4, buttonColumn);
        }
Exemplo n.º 2
0
        private void WorkspaceConfigForm_Load(object sender, EventArgs e)
        {
            DataGridViewTextBoxColumn className = new DataGridViewTextBoxColumn();

            className.Name       = "className";
            className.HeaderText = AdministrationMenuStrings.ClassName;
            className.ReadOnly   = true;
            hoursDataGridView.Columns.Add(className);

            NumericUpDownColumn column = new NumericUpDownColumn();

            column.Name       = "totalHours";
            column.HeaderText = WorkspaceConfigFormStrings.TotalHours;
            column.ReadOnly   = false;
            hoursDataGridView.Columns.Add(column);

            DataGridViewButtonColumn removeBTN = new DataGridViewButtonColumn();

            removeBTN.HeaderText = "";
            removeBTN.Name       = "removeBTN";
            hoursDataGridView.Columns.Add(removeBTN);

            using (loadingForm loading = new loadingForm(RequestAllData))
            {
                loading.ShowDialog();
            }

            try
            {
                classResponse     = JsonConvert.DeserializeObject <classServerResponse>(classRequest);
                allWorkspacesList = JsonConvert.DeserializeObject <workspacesServerResponse>(allWorkspacesRequest);

                if (classResponse.status)
                {
                    if (classResponse.contents.Count < 1)
                    {
                        MessageBox.Show(WorkspaceConfigFormStrings.ClassesNotFound, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                    }
                    else
                    {
                        if (allWorkspacesList.status)
                        {
                            foreach (classContent Class in classResponse.contents)
                            {
                                classesCB.Items.Add(Class.className);
                            }
                        }
                        else
                        {
                            MessageBox.Show(GlobalStrings.Error + ": " + allWorkspacesList.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(GlobalStrings.Error + ": " + classResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Response: " + classResponse + "\n" +
                                "Request:" + classRequest + "\n" +
                                "Error: " + ex.Message + "\n" +
                                "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            if (sentWorkspaceID != 0)
            {
                using (loadingForm loading = new loadingForm(RequestWorkspaceData))
                {
                    loading.ShowDialog();
                }

                try
                {
                    workspaceResponse = JsonConvert.DeserializeObject <workspacesServerResponse>(workspaceRequest);

                    if (workspaceResponse.status)
                    {
                        if (workspaceResponse.contents.Count != 1)
                        {
                            MessageBox.Show(GlobalStrings.GotMoreThanOneEntry, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Close();
                        }
                        else
                        {
                            this.Text = String.Format(WorkspaceConfigFormStrings.FormTitle, workspaceResponse.contents[0].workspaceName);
                            WorkspaceNameTOPBox.Text = workspaceResponse.contents[0].workspaceName;
                            workspaceNameTB.Text     = workspaceResponse.contents[0].workspaceName;

                            readCheck.Checked  = workspaceResponse.contents[0].read;
                            writeCheck.Checked = workspaceResponse.contents[0].write;


                            if (workspaceResponse.contents[0].hours != null)
                            {
                                foreach (hoursContent item in workspaceResponse.contents[0].hours)
                                {
                                    DataGridViewRow         row    = new DataGridViewRow();
                                    DataGridViewTextBoxCell TBcell = new DataGridViewTextBoxCell();
                                    TBcell.Value = classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className;
                                    classesCB.Items.Remove(classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className);
                                    NumericUpDownCell NumUpDownCell = new NumericUpDownCell();
                                    NumUpDownCell.Value = item.totalHours;
                                    DataGridViewButtonCell BTNCell = new DataGridViewButtonCell();
                                    BTNCell.Tag   = classResponse.contents.FindIndex(x => x.classID == item.classID);
                                    BTNCell.Value = WorkspaceConfigFormStrings.RemoveBTN;

                                    row.Cells.Add(TBcell);
                                    row.Cells.Add(NumUpDownCell);
                                    row.Cells.Add(BTNCell);

                                    hoursDataGridView.Rows.Add(row);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(GlobalStrings.Error + ": " + workspaceResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Workspace Response: " + workspaceResponse + "\n" +
                                    "Workspace Request:" + workspaceRequest + "\n" +
                                    "Error: " + ex.Message + "\n" +
                                    "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                }
            }
            else
            {
                this.Text = WorkspaceConfigFormStrings.NewWorkspaceTitle;
                WorkspaceNameTOPBox.Text = WorkspaceConfigFormStrings.NewWorkspace;
            }
        }