예제 #1
0
        private void CreateANote_Load(object sender, EventArgs e)
        {
            // header part
            UserBLL   userBLL   = new UserBLL();
            DataTable dataTable = userBLL.getUserDetails(FormLoaderClass._username);

            lblUserFullName.Text = dataTable.Rows[0][0].ToString() + dataTable.Rows[0][1].ToString();
            lblUserType.Text     = dataTable.Rows[0][2].ToString();

            // load categories
            CategoriesBLL categoriesBLL = new CategoriesBLL();

            cboNoteCategory.DataSource    = categoriesBLL.loadCategories(FormLoaderClass._username);
            cboNoteCategory.DisplayMember = "categoryName";
            cboNoteCategory.ValueMember   = "categoryId";
        }
예제 #2
0
        private void loadStickyNotes(bool isSearch, String searchDate, String searchTitle, String isStickyorCompletedorAll, int status)
        {
            // sticky notes load codes here
            int x = 10, y = 10; // initial coordinates of panel
            int panelSpacing = 10;
            int panelWidth   = this.panelParentStickyNotes.Width;
            int panelHeight  = this.panelParentStickyNotes.Height;

            formHeight = this.panelHeader.Height + this.panelEnableDisable.Height + this.panelNoteTitle.Height + this.panelParentStickyNotes.Height;

            int totalNotesCount = stickyNotesBLL.countNotes(isSearch, searchDate, searchTitle, isStickyorCompletedorAll, status);

            if (totalNotesCount == 0)
            {
                MessageBox.Show("Notes list empty !!!");
            }
            int startNoteCount = 0;

            DataTable dataTable = null;

            if (totalNotesCount > 0)
            {
                dataTable = stickyNotesBLL.loadStickyOrCompletedorAll(isSearch, searchDate, searchTitle, isStickyorCompletedorAll, status);
            }

            // display starts here
            while (startNoteCount < totalNotesCount)
            {
                int    nId               = int.Parse(dataTable.Rows[startNoteCount][0].ToString());
                String nDate             = dataTable.Rows[startNoteCount][1].ToString();
                String nTitle            = dataTable.Rows[startNoteCount][2].ToString();
                String nContent          = dataTable.Rows[startNoteCount][3].ToString();
                String nCompletionStatus = dataTable.Rows[startNoteCount][4].ToString();
                String nStickyStatus     = dataTable.Rows[startNoteCount][5].ToString();
                String nCategoryName     = dataTable.Rows[startNoteCount][6].ToString();

                // object initialization starts
                Label    lblNoteId   = new Label();
                TextBox  txtTitle    = new TextBox();
                TextBox  txtContent  = new TextBox();
                ComboBox cboCategory = new ComboBox();
                // object initialization ends

                Panel panelStickyNote = new Panel();
                panelStickyNote.Name = "panelStickyNote";
                panelStickyNote.Size = new Size(200, 304);

                panelStickyNote.MouseHover += (s, ea) =>
                {
                    Button btnUpdate = new Button();
                    btnUpdate.BackColor                 = Color.Transparent;
                    btnUpdate.BackgroundImage           = global::ElvinShrestha_StickyNotes.Properties.Resources.refreshButton_white;
                    btnUpdate.BackgroundImageLayout     = ImageLayout.Stretch;
                    btnUpdate.FlatStyle                 = FlatStyle.Flat;
                    btnUpdate.FlatAppearance.BorderSize = 0;
                    btnUpdate.UseVisualStyleBackColor   = false;
                    btnUpdate.Location = new Point(160, 270);
                    btnUpdate.Name     = "btnUpdate";
                    btnUpdate.Size     = new Size(25, 23);
                    btnUpdate.TabIndex = 12;
                    btnUpdate.UseVisualStyleBackColor = true;
                    btnUpdate.MouseEnter += (s1, ea1) =>
                    {
                        btnUpdate.BackColor       = Color.White;
                        btnUpdate.BackgroundImage = global::ElvinShrestha_StickyNotes.Properties.Resources.refreshButton_black;
                    };
                    btnUpdate.MouseLeave += (s1, ea1) =>
                    {
                        btnUpdate.BackColor       = Color.Transparent;
                        btnUpdate.BackgroundImage = global::ElvinShrestha_StickyNotes.Properties.Resources.refreshButton_white;
                    };
                    btnUpdate.Click += (s1, ea1) =>
                    {
                        int noteId = int.Parse(lblNoteId.Text);

                        stickyNotesBLL.updateNote(noteId, txtTitle.Text, txtContent.Text, (int)cboCategory.SelectedValue);
                        panelParentStickyNotes.Controls.Clear();
                        loadStickyNotes(false, "null", "null", isStickyorCompletedorAll, status);
                    };

                    panelStickyNote.Controls.Add(btnUpdate);
                };

                if ((x + panelStickyNote.Width) < panelWidth)
                {
                    panelStickyNote.Location  = new Point(x, y);
                    panelStickyNote.BackColor = Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(76)))), ((int)(((byte)(35)))));

                    // hidden lblNoteId
                    // global object for stickyNote load
                    lblNoteId.Name      = "lblNoteId";
                    lblNoteId.Location  = new Point(3, 23);
                    lblNoteId.Text      = nId.ToString();
                    lblNoteId.ForeColor = Color.White;
                    lblNoteId.Size      = new Size(62, 16);
                    lblNoteId.AutoSize  = true;
                    lblNoteId.Visible   = false;

                    // chkSticky
                    CheckBox chkSticky = new CheckBox();
                    chkSticky.AutoSize  = true;
                    chkSticky.ForeColor = Color.White;
                    chkSticky.Location  = new Point(4, 4);
                    chkSticky.Name      = "chkSticky";
                    chkSticky.Size      = new Size(57, 20);
                    chkSticky.TabIndex  = 0;
                    chkSticky.Text      = "Sticky";
                    chkSticky.UseVisualStyleBackColor = true;
                    if (nStickyStatus == "True")
                    {
                        chkSticky.Checked = true;
                    }
                    chkSticky.CheckedChanged += (s, ea) =>
                    {
                        int  noteId   = int.Parse(lblNoteId.Text);
                        bool isSticky = false;

                        if (chkSticky.Checked)
                        {
                            isSticky = true;
                        }

                        stickyNotesBLL.updateNoteStickyStatus(noteId, isSticky);

                        // refresh
                        panelParentStickyNotes.Controls.Clear();
                        loadStickyNotes(false, "null", "null", isStickyorCompletedorAll, status);
                    };

                    // chkCompleted
                    CheckBox chkCompleted = new CheckBox();
                    chkCompleted.AutoSize  = true;
                    chkCompleted.ForeColor = Color.White;
                    chkCompleted.Location  = new Point(108, 4);
                    chkCompleted.Name      = "chkCompleted";
                    chkCompleted.Size      = new Size(89, 20);
                    chkCompleted.TabIndex  = 1;
                    chkCompleted.Text      = "Completed";
                    chkCompleted.UseVisualStyleBackColor = true;
                    if (nCompletionStatus == "True")
                    {
                        chkCompleted.Checked = true;
                    }
                    chkCompleted.CheckedChanged += (s, ea) =>
                    {
                        int  noteId      = int.Parse(lblNoteId.Text);
                        bool isCompleted = false;

                        if (chkCompleted.Checked)
                        {
                            isCompleted = true;
                        }

                        stickyNotesBLL.updateNoteCompletionStatus(noteId, isCompleted);

                        // refresh
                        panelParentStickyNotes.Controls.Clear();
                        loadStickyNotes(false, "null", "null", isStickyorCompletedorAll, status);
                    };

                    // lblCategory
                    Label lblCategory = new Label();
                    lblCategory.AutoSize  = true;
                    lblCategory.ForeColor = Color.White;
                    lblCategory.Location  = new Point(4, 39);
                    lblCategory.Name      = "lblCategory";
                    lblCategory.Size      = new Size(62, 16);
                    lblCategory.TabIndex  = 2;
                    lblCategory.Text      = "Category:";

                    // lblCategoryContent
                    Label lblCategoryContent = new Label();
                    lblCategoryContent.AutoSize  = true;
                    lblCategoryContent.ForeColor = Color.White;
                    lblCategoryContent.Location  = new Point(64, 39);
                    lblCategoryContent.Name      = "lblCategoryContent";
                    lblCategoryContent.Size      = new Size(62, 16);
                    lblCategoryContent.Text      = nCategoryName;

                    // lnklblCategoryEdit
                    LinkLabel lnklblCategoryEdit = new LinkLabel();
                    lnklblCategoryEdit.AutoSize  = true;
                    lnklblCategoryEdit.LinkColor = Color.White;
                    lnklblCategoryEdit.Location  = new Point(4, 58);
                    lnklblCategoryEdit.Name      = "lnklblCategoryEdit";
                    lnklblCategoryEdit.Size      = new Size(62, 16);
                    lnklblCategoryEdit.TabIndex  = 3;
                    lnklblCategoryEdit.Text      = "Click to edit Category";
                    lnklblCategoryEdit.Click    += (s, ea) =>
                    {
                        lnklblCategoryEdit.Visible = false;
                        cboCategory.Visible        = true;
                        cboCategory.Focus();
                    };

                    // cboCategory
                    // global object for stickyNote load
                    cboCategory.Font = new Font("Century Gothic", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
                    cboCategory.FormattingEnabled = true;
                    cboCategory.Location          = new Point(4, 58);
                    cboCategory.Name          = "cboCategory";
                    cboCategory.Size          = new Size(193, 24);
                    cboCategory.TabIndex      = 3;
                    cboCategory.DropDownStyle = ComboBoxStyle.DropDownList;
                    CategoriesBLL categoriesBLL = new CategoriesBLL();
                    cboCategory.DataSource    = categoriesBLL.loadCategories(FormLoaderClass._username);
                    cboCategory.DisplayMember = "categoryName";
                    cboCategory.ValueMember   = "categoryId";
                    cboCategory.Visible       = false;

                    // lblTitle
                    Label lblTitle = new Label();
                    lblTitle.AutoSize  = true;
                    lblTitle.ForeColor = Color.White;
                    lblTitle.Location  = new Point(4, 85);
                    lblTitle.Name      = "lblTitle";
                    lblTitle.Size      = new Size(28, 16);
                    lblTitle.TabIndex  = 4;
                    lblTitle.Text      = "Title";

                    // txtTitle
                    // global object for stickyNote load
                    txtTitle.Location = new Point(3, 104);
                    txtTitle.Name     = "txtTitle";
                    txtTitle.Size     = new Size(193, 21);
                    txtTitle.TabIndex = 5;
                    txtTitle.Text     = nTitle;

                    // lblContent
                    Label lblContent = new Label();
                    lblContent.AutoSize  = true;
                    lblContent.ForeColor = Color.White;
                    lblContent.Location  = new Point(1, 128);
                    lblContent.Name      = "lblContent";
                    lblContent.Size      = new Size(53, 16);
                    lblContent.TabIndex  = 6;
                    lblContent.Text      = "Content";

                    // txtContent
                    // global object for stickyNote load
                    txtContent.Location   = new Point(3, 147);
                    txtContent.Multiline  = true;
                    txtContent.Name       = "txtContent";
                    txtContent.Size       = new Size(193, 90);
                    txtContent.TabIndex   = 7;
                    txtContent.ScrollBars = ScrollBars.Vertical;
                    txtContent.Text       = nContent;

                    // lblDateCreated
                    Label lblDateCreated = new Label();
                    lblDateCreated.AutoSize  = true;
                    lblDateCreated.ForeColor = Color.White;
                    lblDateCreated.Location  = new Point(4, 244);
                    lblDateCreated.Name      = "lblDateCreated";
                    lblDateCreated.Size      = new Size(87, 16);
                    lblDateCreated.TabIndex  = 8;
                    lblDateCreated.Text      = "Date Created:";

                    // lblDateCreatedValue
                    Label lblDateCreatedValue = new Label();
                    lblDateCreatedValue.AutoSize  = true;
                    lblDateCreatedValue.ForeColor = Color.White;
                    lblDateCreatedValue.Location  = new Point(97, 244);
                    lblDateCreatedValue.Name      = "lblDateCreatedValue";
                    lblDateCreatedValue.Size      = new Size(64, 16);
                    lblDateCreatedValue.TabIndex  = 9;
                    lblDateCreatedValue.Text      = nDate;

                    // lblDeleteNote
                    Label lblDeleteNote = new Label();
                    lblDeleteNote.AutoSize  = true;
                    lblDeleteNote.ForeColor = Color.White;
                    lblDeleteNote.Location  = new Point(4, 277);
                    lblDeleteNote.Name      = "lblDeleteNote";
                    lblDeleteNote.Size      = new Size(71, 16);
                    lblDeleteNote.TabIndex  = 10;
                    lblDeleteNote.Text      = "Delete note";

                    // btnDelete
                    Button btnDelete = new Button();
                    btnDelete.BackColor                 = Color.Transparent;
                    btnDelete.BackgroundImage           = global::ElvinShrestha_StickyNotes.Properties.Resources.deleteIcon;
                    btnDelete.BackgroundImageLayout     = ImageLayout.Stretch;
                    btnDelete.FlatStyle                 = FlatStyle.Flat;
                    btnDelete.FlatAppearance.BorderSize = 0;
                    btnDelete.UseVisualStyleBackColor   = false;
                    btnDelete.Location = new Point(86, 270);
                    btnDelete.Name     = "btnDelete";
                    btnDelete.Size     = new Size(25, 23);
                    btnDelete.TabIndex = 11;
                    btnDelete.UseVisualStyleBackColor = true;
                    btnDelete.Click += (s, ea) =>
                    {
                        DialogResult dialogResult = MessageBox.Show("Are you sure ?", "Confirm Delete", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            panelStickyNote.Hide(); // panel hidden but deleted also.
                            int noteId = int.Parse(lblNoteId.Text);
                            stickyNotesBLL.deleteNote(noteId);

                            // refresh sticky notes
                            panelParentStickyNotes.Controls.Clear();
                            loadStickyNotes(isSearch, searchDate, searchTitle, isStickyorCompletedorAll, status);
                        }
                    };
                    btnDelete.MouseEnter += (s, ea) =>
                    {
                        btnDelete.BackColor       = Color.White;
                        btnDelete.BackgroundImage = global::ElvinShrestha_StickyNotes.Properties.Resources.deleteIcon_dark;
                    };
                    btnDelete.MouseLeave += (s, ea) =>
                    {
                        btnDelete.BackColor       = Color.Transparent;
                        btnDelete.BackgroundImage = global::ElvinShrestha_StickyNotes.Properties.Resources.deleteIcon;
                    };


                    // added to panelStickyNote
                    panelStickyNote.Controls.Add(lblNoteId);
                    panelStickyNote.Controls.Add(chkSticky);
                    panelStickyNote.Controls.Add(chkCompleted);
                    panelStickyNote.Controls.Add(lblCategory);
                    panelStickyNote.Controls.Add(lblCategoryContent);
                    panelStickyNote.Controls.Add(lnklblCategoryEdit);
                    panelStickyNote.Controls.Add(cboCategory);
                    panelStickyNote.Controls.Add(lblTitle);
                    panelStickyNote.Controls.Add(txtTitle);
                    panelStickyNote.Controls.Add(lblContent);
                    panelStickyNote.Controls.Add(txtContent);
                    panelStickyNote.Controls.Add(lblDateCreated);
                    panelStickyNote.Controls.Add(lblDateCreatedValue);
                    panelStickyNote.Controls.Add(lblDeleteNote);
                    panelStickyNote.Controls.Add(btnDelete);

                    // added to panelParentStickyNotes
                    panelParentStickyNotes.Controls.Add(panelStickyNote);

                    // coordinate update
                    x = x + panelStickyNote.Width + panelSpacing;
                    startNoteCount = startNoteCount + 1;
                }
                else if ((x + panelStickyNote.Width) >= panelWidth)
                {
                    x = 10;
                    y = y + panelStickyNote.Height + panelSpacing;
                }
            }
        }
예제 #3
0
 private void loadCategories()
 {
     dgvCategories.DataSource = categoriesBLL.loadCategories(FormLoaderClass._username);
 }