Exemplo n.º 1
0
        public void add(object T)
        {
            Item item = (Item)T;

            int uomID    = uomRepository.getID(item.unitOfMeasure);
            int statusID = statusRepository.getID(item.status);

            sqlcmd = new SqlCommand("INSERT INTO Item (Name, ShortName, Alias, Description, Quantity, UOMID, Price, Extension, StatusID, Active) VALUES (@Name, @ShortName, @Alias, @Description, @Quantity, @UOMID, @StatusID, @Active)", Misc.getConn());
            sqlcmd.Parameters.AddWithValue("@Name", item.name);
            sqlcmd.Parameters.AddWithValue("@ShortName", item.shortName);
            sqlcmd.Parameters.AddWithValue("@Alias", item.alias);
            sqlcmd.Parameters.AddWithValue("@Description", item.description);
            sqlcmd.Parameters.AddWithValue("@Quantity", item.quantity);
            sqlcmd.Parameters.AddWithValue("@UOMID", uomID);
            sqlcmd.Parameters.AddWithValue("@StatusID", statusID);
            sqlcmd.Parameters.AddWithValue("@Active", item.active);
            Misc.connOpen();
            sqlcmd.ExecuteNonQuery();
            sqlcmd.Dispose();
        }
Exemplo n.º 2
0
        private void controlNavigator1_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
        {
            // try {
            if (e.Button.Tag.ToString() == "Add")
            {
                toolStripStatusLabel1.Text = "Adding...";
                if (tableLayoutPanel1.RowStyles[2].Height == 1)
                {
                    tableLayoutPanel1.RowStyles[2].Height = 80;
                }
                actionState = "a";
                setControlState(true);
                emptyControls();
                txtUom.Focus();

                BtnAdd.Enabled     = false;
                BtnEdit.Enabled    = false;
                BtnSave.Enabled    = true;
                BtnCancel.Enabled  = true;
                BtnSwitch.Enabled  = false;
                BtnRefresh.Enabled = false;

                controlNavigator1.Buttons.First.Enabled = false;
                controlNavigator1.Buttons.Next.Enabled  = false;
                controlNavigator1.Buttons.Prev.Enabled  = false;
                controlNavigator1.Buttons.Last.Enabled  = false;

                searchControl1.Enabled = false;
                gridControl1.Enabled   = false;
            }
            else if (e.Button.Tag.ToString() == "Edit")
            {
                uomID = repository.getID(txtUom.Text);

                if (tableLayoutPanel1.RowStyles[2].Height == 1)
                {
                    tableLayoutPanel1.RowStyles[2].Height = 80;
                }
                actionState = "e";
                setControlState(true);

                txtUom.Focus();
                BtnAdd.Enabled     = false;
                BtnEdit.Enabled    = false;
                BtnSave.Enabled    = true;
                BtnCancel.Enabled  = true;
                BtnSwitch.Enabled  = false;
                BtnRefresh.Enabled = false;

                controlNavigator1.Buttons.First.Enabled = false;
                controlNavigator1.Buttons.Next.Enabled  = false;
                controlNavigator1.Buttons.Prev.Enabled  = false;
                controlNavigator1.Buttons.Last.Enabled  = false;

                searchControl1.Enabled = false;
                gridControl1.Enabled   = false;
            }
            else if (e.Button.Tag.ToString() == "Save")
            {
                if (actionState == "e")
                {
                    toolStripStatusLabel1.Text = "Editing...";

                    UnitOfMeasure uom = new UnitOfMeasure {
                        name      = txtUom.Text,
                        shortName = txtShortName.Text,
                        active    = cbActive.Checked
                    };

                    repository.update(uomID, uom);
                }
                else if (actionState == "a")
                {
                    toolStripStatusLabel1.Text = "Saving...";

                    if (!verifyInput())
                    {
                        return;
                    }

                    UnitOfMeasure uom = new UnitOfMeasure {
                        name      = txtUom.Text,
                        shortName = txtShortName.Text,
                        active    = cbActive.Checked
                    };

                    repository.add(uom);
                }

                actionState = "a";

                gridControl1.DataSource = repository.loadData();
                setControlState(false);
                BtnSave.Enabled    = false;
                BtnEdit.Enabled    = true;
                BtnAdd.Enabled     = true;
                BtnCancel.Enabled  = false;
                BtnSwitch.Enabled  = true;
                BtnRefresh.Enabled = true;

                controlNavigator1.Buttons.First.Enabled = true;
                controlNavigator1.Buttons.Next.Enabled  = true;
                controlNavigator1.Buttons.Prev.Enabled  = true;
                controlNavigator1.Buttons.Last.Enabled  = true;

                searchControl1.Enabled     = true;
                gridControl1.Enabled       = true;
                toolStripStatusLabel1.Text = "Saved";
            }
            else if (e.Button.Tag.ToString() == "Cancel")
            {
                setControlState(false);
                actionState        = "a";
                BtnAdd.Enabled     = true;
                BtnEdit.Enabled    = true;
                BtnSave.Enabled    = false;
                BtnCancel.Enabled  = false;
                BtnSwitch.Enabled  = true;
                BtnRefresh.Enabled = true;

                controlNavigator1.Buttons.First.Enabled = true;
                controlNavigator1.Buttons.Next.Enabled  = true;
                controlNavigator1.Buttons.Prev.Enabled  = true;
                controlNavigator1.Buttons.Last.Enabled  = true;

                searchControl1.Enabled = true;
                gridControl1.Enabled   = true;

                toolStripStatusLabel1.Text = "Done";
            }
            else if (e.Button.Tag.ToString() == "Refresh")
            {
                toolStripStatusLabel1.Text = "Refreshing...";
                gridControl1.DataSource    = repository.loadData();
                toolStripStatusLabel1.Text = "Done";
            }
            else if (e.Button.Tag.ToString() == "Switch")
            {
                if (tableLayoutPanel1.RowStyles[2].Height == 80)
                {
                    tableLayoutPanel1.RowStyles[2].Height = 1;
                }
                else
                {
                    tableLayoutPanel1.RowStyles[2].Height = 80;
                }
            }
            //} catch {

            //}
        }