コード例 #1
0
        private void btnCreateOrEdit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbxName.Text) || string.IsNullOrEmpty(tbxValence.Text))
            {
                DialogsManager.ShowError("Not all required fields are filled.");
                return;
            }

            Dopant dopant = new Dopant(0, tbxName.Text, tbxValence.Text);

            string message;

            if (this._currentDopant == null)
            {
                this._dopantRepository.InsertDopant(dopant);
                message = "New dopant was created.";
            }
            else
            {
                this._dopantRepository.UpdateDopantWithId(this._currentDopant.Id, dopant);
                message = "Changes were successfully saved.";
            }

            this.DialogResult = DialogResult.OK;
            DialogsManager.ShowSuccessAndClose(message, this);
        }
コード例 #2
0
        public CreateOrEditDopand(int Id = 0)
        {
            InitializeComponent();

            if (Id != 0)
            {
                this._currentDopant = this._dopantRepository.GetDopantById(Id);
                this.Text           = "Edit dopand " + this._currentDopant.Name;
            }
        }
コード例 #3
0
        public Dopant InsertDopant(Dopant dopant)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@Name", dopant.Name);
            parameters.Add("@Valence", dopant.Valence);

            Dopant result = GetDopantById(InsertElement(parameters, _insertDopantQuery));

            return(result);
        }
コード例 #4
0
        public Dopant GetDopantById(int id)
        {
            Dopant resultDopant = new Dopant();

            object[] values = GetElementById(id, _getDopantByIdQuery);

            if (values != null)
            {
                resultDopant.Id      = (int)values[0];
                resultDopant.Name    = (string)values[1];
                resultDopant.Valence = (string)values[2];

                return(resultDopant);
            }
            return(null);
        }
コード例 #5
0
        public Dopant UpdateDopantWithId(int id, Dopant dopant)
        {
            Dopant dopantBeforeUpdating = GetDopantById(id);

            var newDopant = new Dictionary <string, object>();

            newDopant.Add("@Name", dopant.Name);
            newDopant.Add("@Valence", dopant.Valence);

            UpdateElementWithId(id, newDopant, _updateDopantWithIdQuery);

            Dopant dopantAfterUpdating = GetDopantById(id);

            if (dopantBeforeUpdating != dopantAfterUpdating)
            {
                return(dopantAfterUpdating);
            }
            return(null);
        }
コード例 #6
0
        private void FillInfoLabelText(int currentId)
        {
            if (this.tbdropdShowSettings.Text == "Matrixes")
            {
                Matrix matrix = _matrixRepository.GetMatrixById(currentId);

                this.lblInfo.Text = "Selected: " + matrix.ToString();
            }
            else if (this.tbdropdShowSettings.Text == "Dopants")
            {
                Dopant dopant = _dopantRepository.GetDopantById(currentId);

                this.lblInfo.Text = "Selected: " + dopant.ToString();
            }
            else if (this.tbdropdShowSettings.Text == "Compounds")
            {
                Matrix matrix = _matrixRepository.GetMatrixById(currentId);

                this.lblInfo.Text = "Selected: " + matrix.ToString();
            }
        }