示例#1
0
        private void buttonAddPosition_Click(object sender, EventArgs e)
        {
            MalfMapper mm = new MalfMapper();

            if (malf == null)
            {
                malf = new Malfunctions(textBoxDescription.Text, Convert.ToDouble(textBoxPrice.Text),
                                        Converter.ConvertUnit(comboBoxUnit.Text));
                if (formForSelect != null && Form1.WindowIndex == WindowsStruct.MalfAdd)
                {
                    malf = mm.Insert(malf);
                }
                else if (formForSelect != null && Form1.WindowIndex == WindowsStruct.SpareAdd)
                {
                    malf.MalfOrSpare = 1;
                    malf             = mm.Insert(malf);
                }
                else
                {
                    malf = mm.Insert(malf);
                }
            }
            else
            {
                malf.Description = textBoxDescription.Text;
                malf.Unit        = Converter.ConvertUnit(comboBoxUnit.Text);
                malf.Cost        = Convert.ToDouble(textBoxPrice.Text);
                if (formForSelect != null && Form1.WindowIndex == WindowsStruct.MalfAdd)
                {
                    mm.Update(malf);
                }
                else if (formForSelect != null && Form1.WindowIndex == WindowsStruct.SpareAdd)
                {
                    malf.MalfOrSpare = 1;
                    mm.Update(malf);
                }
            }
            if (formForSelect != null && Form1.WindowIndex == WindowsStruct.MalfAdd ||
                Form1.WindowIndex == WindowsStruct.SpareAdd)
            {
                Form1.AddListMalfunctionsInGrid(formForSelect.dataGridView, Queries.MalfunctionsView);
                Form1.SelectIndex = 0;
                Malfunctions malfInRepair = formForSelect.formAddRepair.repair.ListOfMalf.
                                            Find(m => m.IdMalf == malf.IdMalf);
                if (malfInRepair != null)
                {
                    malfInRepair.Unit        = malf.Unit;
                    malfInRepair.Description = malf.Description;
                }
                formForSelect.textBoxSearch.Clear();
                formForSelect.textBoxSearch.Text = textBoxDescription.Text;
                this.Close();
                return;
            }
            mm.Update(malf);
            this.Close();
            Form1.AddListMalfunctionsInGrid(mainForm.dataGridView, Queries.MalfunctionsView);
            mainForm.dataGridView.ClearSelection();
        }
        private void AddMalfOrSparesInRepair()
        {
            Malfunctions malfAdd = new MalfMapper().Get(formForSelect.dataGridView.SelectedRows[0].Cells[0].Value.ToString());

            malfAdd.Number = (int)numberUpDown.Value;
            Malfunctions malf = formAddRepair.repair.ListOfMalf.Find(m => m.IdMalf == malfAdd.IdMalf);

            if (malf == null)
            {
                formAddRepair.repair.AddMalfInList(malfAdd);
            }
            else
            {
                malf.Number = (int)numberUpDown.Value;
            }
            formAddRepair.repair.CalculateTotalPrice();
        }
        private void btnDeletePosition_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count == 0)
            {
                return;
            }
            string id = dataGridView.SelectedRows[0].Cells[0].Value.ToString();

            if (Form1.WindowIndex == WindowsStruct.MalfView || Form1.WindowIndex == WindowsStruct.SpareView)
            {
                Malfunctions malf = new MalfMapper().Get(id);
                formAddRepair.repair.RemoveMalfFromList(malf);
            }
            else if (Form1.WindowIndex == WindowsStruct.WorkerView)
            {
                Employee emp = new EmployeeMapper().Get(id);
                formAddRepair.repair.RemovePersonalFromList(emp);
            }
            RefreshDataInGrid();
        }