Example #1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtName.Text))
            {
                frmMessageBoxFillNull frm = new frmMessageBoxFillNull();
                frm.ShowDialog();
            }
            else
            {
                if (flag == true)
                {
                    if ((cboCategory.SelectedIndex == -1) || (cboType.SelectedIndex == -1))
                    {
                        frmMessageBoxCategory frm = new frmMessageBoxCategory();
                        frm.ShowDialog();
                    }
                    else
                    {
                        frmMessageBoxSave frm = new frmMessageBoxSave();
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            String name = txtName.Text;
                            AlmacenDisecWS.category c = (AlmacenDisecWS.category)cboCategory.SelectedItem;
                            AlmacenDisecWS.family   f = new AlmacenDisecWS.family();
                            f.name_family = name;
                            f.category    = c;


                            btnModify.Enabled             = true;
                            operation                     = true;
                            dgvSearch.AutoGenerateColumns = false;
                            int    a  = 0;
                            string a1 = cboType.SelectedItem.ToString();
                            if (cboType.SelectedItem.ToString() == "MATERIAL")
                            {
                                a = 1;
                            }
                            else if (cboType.SelectedItem.ToString() == "HERRAMIENTA")
                            {
                                a = 2;
                            }


                            int result = serviceDA.insertFamily(f, a);
                            dgvSearch.DataSource = serviceDA.queryAllFamily(c.category_id);
                            cmbSearch.Text       = cboCategory.Text;
                            reiniciar();
                        }
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(txtId.Text) || String.IsNullOrEmpty(cboCategory.Text))
                    {
                        frmMessageBoxFillNull frm2 = new frmMessageBoxFillNull();
                        frm2.ShowDialog();
                    }
                    else
                    {
                        frmMessageBoxSave frm = new frmMessageBoxSave();
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            int    id   = Int32.Parse(txtId.Text);
                            String name = txtName.Text;
                            AlmacenDisecWS.category c = (AlmacenDisecWS.category)cboCategory.SelectedItem;
                            AlmacenDisecWS.family   f = new AlmacenDisecWS.family();
                            f.id_family   = id;
                            f.name_family = name;
                            f.category    = c;
                            int result = serviceDA.updateFamily(f);
                            dgvSearch.AutoGenerateColumns = false;
                            dgvSearch.DataSource          = serviceDA.queryAllFamily(c.category_id);
                            cmbSearch.Text = cboCategory.Text;
                            reiniciar();
                            operation         = true;
                            btnModify.Enabled = true;
                        }
                    }
                }
            }
        }