Esempio n. 1
0
        private void EngineArrToForm(Engine curEngine)
        {
            EngineArr engineArr = new EngineArr();

            engineArr.Fill();

            listbox_Engine.DataSource    = engineArr;
            listbox_Engine.ValueMember   = "Id";
            listbox_Engine.DisplayMember = "Name";

            if (curEngine != null)
            {
                listbox_Engine.SelectedValue = curEngine.Id;
            }
        }
Esempio n. 2
0
        public void EngineArrToForm(Engine curEngine)
        {
            EngineArr engineArr = new EngineArr();

            engineArr.Fill();

            cmb_Engine.DataSource    = engineArr;
            cmb_Engine.ValueMember   = "Id";
            cmb_Engine.DisplayMember = "Name";

            if (curEngine != null)
            {
                cmb_Engine.SelectedValue = curEngine.Id;
            }
        }
Esempio n. 3
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (CheckForm())
            {
                Engine engine = new Engine();
                engine = FormToEngine();

                EngineArr oldEngineArr = new EngineArr();
                oldEngineArr.Fill();

                if (!oldEngineArr.IsContain(engine.Name))
                {
                    if (engine.Id == 0)
                    {
                        if (engine.Insert())
                        {
                            MessageBox.Show("Data saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearForm();

                            EngineArr engineArr = new EngineArr();
                            engineArr.Fill();
                            engine = engineArr.GetEngineWithMaxId();

                            EngineArrToForm(engine);
                        }
                    }
                    else
                    {
                        if (engine.Update())
                        {
                            MessageBox.Show("Data updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearForm();

                            EngineArr engineArr = new EngineArr();
                            engineArr.Fill();
                            engine = engineArr.GetEngineWithMaxId();
                            EngineArrToForm(engine);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Engine already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ClearForm();
                }
            }
        }