Exemplo n.º 1
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     this._editSubcontractor = null;
     this._operationMode     = OperationModesEnum.None;
     this.panel1.Enabled     = false;
     this.btnAddNew.Focus();
 }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.txtSubcontractorName.Text.Trim() == "")
            {
                MessageBox.Show("Please enter subcontractor's name", "Error", MessageBoxButtons.OK
                                , MessageBoxIcon.Exclamation);
                this.txtSubcontractorName.Focus();
                return;
            }
            decimal?id   = this._operationMode == OperationModesEnum.AddNew ? 0 : this._editSubcontractor.Subcontractor_ID;
            string  name = this.txtSubcontractorName.Text.Trim();

            DSLOGS.SubcontractorsDataTable dtDuplicateSubcontractors = this.subcontractorsTableAdapter.GetDataByNameByNotID(id, name);
            if (dtDuplicateSubcontractors.Rows.Count > 0)
            {
                MessageBox.Show($"Subcontractor with name {name} already exists. Please enter a different name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtSubcontractorName.Focus();
                return;
            }

            if (this._operationMode == OperationModesEnum.AddNew)
            {
                int x = this.subcontractorsTableAdapter.Insert(ref id, name, this.txtPhone1.Text.Trim(), this.txtPhone2.Text.Trim());
                if (x == 1)
                {
                    MessageBox.Show("Subcontractor data saved successfully", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.ClearControls();

                    this._operationMode = OperationModesEnum.None;
                    this.panel1.Enabled = false;
                    this.RetrieveData();
                    this.btnAddNew.Focus();
                }
            }
            else if (this._operationMode == OperationModesEnum.Edit)
            {
                int x = this.subcontractorsTableAdapter.Update(name, this.txtPhone1.Text.Trim(), this.txtPhone2.Text.Trim()
                                                               , this._editSubcontractor.Active, id);
                if (x == 1)
                {
                    MessageBox.Show("Subcontractor data updated successfully", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.ClearControls();

                    this._editSubcontractor = null;
                    this._operationMode     = OperationModesEnum.None;
                    this.panel1.Enabled     = false;
                    this.RetrieveData();
                    this.btnAddNew.Focus();
                }
            }
        }
Exemplo n.º 3
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     if (this.dgvSubcontractors.CurrentRow == null)
     {
         return;
     }
     this._editSubcontractor =
         this.dSLOGS.Subcontractors.Select(this.dSLOGS.Subcontractors.Subcontractor_IDColumn.ColumnName
                                           + "=" + this.dgvSubcontractors.CurrentRow.Cells[0].Value)[0] as DSLOGS.SubcontractorsRow;
     this._operationMode = OperationModesEnum.Edit;
     this.RetrieveSubcontractor();
     this.panel1.Enabled = true;
     this.txtSubcontractorName.Focus();
     this.txtSubcontractorName.SelectAll();
 }