Exemplo n.º 1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                id = Convert.ToInt32(lvInfo.SelectedItems[0].Text);
                if (onFieldDisable == false)
                {
                    onFieldDisable = true;
                    cancel         = true;
                    buttons        = "edit";
                    Fields(); // enable fields
                    Buttons();

                    txtName.Text   = lvInfo.SelectedItems[0].SubItems[1].Text;
                    cboGender.Text = lvInfo.SelectedItems[0].SubItems[2].Text;
                }
                else
                {
                    if (onFieldDisable == true)
                    {
                        string name   = txtName.Text;
                        string gender = cboGender.Text;
                        if (name == "" || gender == "")
                        {
                            MessageBox.Show("Please enter the name and gender", "SAMPLE CRUD", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        else
                        {
                            Entity.variables ent = new Entity.variables();
                            ent.name   = name;
                            ent.gender = gender;
                            ent.id     = id;
                            string str = Model.userInfoModel.EditUserInfo(ent);
                            if (str == "success")
                            {
                                loadData();
                                MessageBox.Show("successfully update", "SAMPLE CRUD", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                onFieldDisable = false;
                                Fields();
                                buttons = "default";
                                Buttons();
                                cancel = false;
                                clearFields();
                            }
                            else
                            {
                                MessageBox.Show(str);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please select the row you want to edit", "Select", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (onFieldDisable == false)
            {
                onFieldDisable = true;
                cancel         = true;
                buttons        = "add";
                Fields(); // enable fields
                Buttons();
            }
            else
            {
                if (onFieldDisable == true)
                {
                    string name   = txtName.Text;
                    string gender = cboGender.Text;
                    if (name == "" || gender == "")
                    {
                        MessageBox.Show("Please enter name and gender", "SAMPLE CRUD", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else
                    {
                        Entity.variables ent = new Entity.variables();
                        ent.name   = name;
                        ent.gender = gender;
                        string str = Model.userInfoModel.addUserInfo(ent);
                        if (str == "success")
                        {
                            loadData();
                            MessageBox.Show("successfully added", "SAMPLE CRUD", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            onFieldDisable = false;
                            Fields();
                            buttons = "default";
                            Buttons();
                            cancel = false;
                            clearFields();
                        }
                        else
                        {
                            MessageBox.Show(str);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static Boolean cancel         = false; // cancel add/edit

        public void loadData()
        {
            str = Model.userInfoModel.getUserInfo(pageNumber);
            if (str == "success")
            {
                totalCount = config.records.Count;
                if (totalCount > 0)
                {
                    lvInfo.Items.Clear();
                    for (int count = 0; count < config.records.Count; count++)
                    {
                        ListViewItem item = new ListViewItem(config.records[count].id.ToString());
                        item.SubItems.Add(config.records[count].name.ToString());
                        item.SubItems.Add(config.records[count].gender.ToString());
                        lvInfo.Items.Add(item);

                        itemNewId = config.records[count].id;
                    }

                    Model.userInfoModel.getTotalCount();
                    Entity.variables variables = new Entity.variables();


                    if (itemNewId == itemOldId)
                    {
                        // no more data
                    }
                    else
                    {
                        itemOldId    = itemNewId;
                        totalPage    = ((config.records[0].totalCount / Entity.variables.sizePerPage) + 1);
                        lblPage.Text = "Page " + pageNumber + " of " + ((config.records[0].totalCount / Entity.variables.sizePerPage) + 1).ToString();
                    }
                }
            }
            else
            {
            }
        }