예제 #1
0
        private void ColorTypesArrToForm(ColorType curColorTypes)
        {
            ColorTypeArr colorTypeArr = new ColorTypeArr();

            colorTypeArr.Fill();

            listbox_ColorTypes.ValueMember   = "Id";
            listbox_ColorTypes.DisplayMember = "Name";
            listbox_ColorTypes.DataSource    = colorTypeArr;

            if (curColorTypes != null)
            {
                listbox_ColorTypes.SelectedValue = curColorTypes.Id;
            }
        }
예제 #2
0
        public void ColorTypesArrToForm(ColorType curColorType)
        {
            ColorTypeArr colrTypeArr = new ColorTypeArr();

            colrTypeArr.Fill();

            cmb_ColorType.ValueMember   = "Id";
            cmb_ColorType.DisplayMember = "Name";
            cmb_ColorType.DataSource    = colrTypeArr;


            if (curColorType != null)
            {
                cmb_ColorType.SelectedValue = curColorType.Id;
            }
        }
예제 #3
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (CheckForm())
            {
                ColorType colorType = new ColorType();
                colorType = FormToColorTypes();

                ColorTypeArr oldColorTypesArr = new ColorTypeArr();
                oldColorTypesArr.Fill();

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

                            ColorTypeArr colorTypes = new ColorTypeArr();
                            colorTypes.Fill();
                            colorType = colorTypes.GetColorTypesWithMaxId();

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

                            ColorTypeArr carColorArr = new ColorTypeArr();
                            carColorArr.Fill();
                            colorType = carColorArr.GetColorTypesWithMaxId();
                            ColorTypesArrToForm(null);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Color Type already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ClearForm();
                }
            }
        }