Beispiel #1
0
 private void OfficialDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     StaftextBox.Text            = OfficialDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
     StaffNatext.Text            = OfficialDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
     DeptcomboBox.SelectedIndex  = DeptcomboBox.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString());
     DesigcomboBox.SelectedIndex = DesigcomboBox.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[4].Value.ToString());
     EXPText.Text = OfficialDataGridView.Rows[e.RowIndex].Cells[5].Value.ToString();
     BloodcomboBox.SelectedIndex = BloodcomboBox.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[6].Value.ToString());
     joindateTimePicker.Value    = Convert.ToDateTime(OfficialDataGridView.Rows[e.RowIndex].Cells[7].Value.ToString());
     NationaText.Text            = OfficialDataGridView.Rows[e.RowIndex].Cells[8].Value.ToString();
     Statuscombo.SelectedIndex   = Statuscombo.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[9].Value.ToString());
 }
Beispiel #2
0
        private void OFSaveButton_Click(object sender, EventArgs e)
        {
            string query = ""; int DepartmentKey = ((KeyValuePair <int, string>)DeptcomboBox.SelectedItem).Key;
            String DepartmentValue = ((KeyValuePair <int, string>)DeptcomboBox.SelectedItem).Value;
            String DesignationValue = ((KeyValuePair <int, string>)DesigcomboBox.SelectedItem).Value;
            String BloodValue = ((KeyValuePair <int, string>)BloodcomboBox.SelectedItem).Value;
            String StatusValue = ((KeyValuePair <int, string>)Statuscombo.SelectedItem).Value;
            string que = ""; int DesignationKey = ((KeyValuePair <int, string>)DesigcomboBox.SelectedItem).Key;
            string qu = ""; int BloodKey = ((KeyValuePair <int, string>)BloodcomboBox.SelectedItem).Key;
            string q = ""; int StatusKey = ((KeyValuePair <int, string>)Statuscombo.SelectedItem).Key;

            if (StaftextBox.Text == "")
            {
                query = "SELECT Count(*) AS Count FROM Official_Info";
                int rowsCount = DbAccess.NumberOfRecords(query) + 1;
                stfID = Convert.ToInt32(DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + rowsCount.ToString());
            }
            if (StaffNatext.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Staff Name");
                StaffNatext.Focus();
                return;
            }

            if (DepartmentKey < 1)
            {
                MessageBox.Show("Please Enter Department");
                DeptcomboBox.Focus();
                return;
            }
            if (DesignationKey < 1)
            {
                MessageBox.Show("Please Enter designation");
                DesigcomboBox.Focus();
                return;
            }

            if (EXPText.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Experience");
                EXPText.Focus();
                return;
            }
            if (BloodKey < 1)
            {
                MessageBox.Show("Please Enter BloodGroup");
                BloodcomboBox.Focus();
                return;
            }
            if (joindateTimePicker.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Time");
                joindateTimePicker.Focus();
                return;
            }
            if (NationaText.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Nationality");
                NationaText.Focus();
                return;
            }
            if (StatusKey < 1)
            {
                MessageBox.Show("Please Enter Status");
                Statuscombo.Focus();
                return;
            }
            try
            {
                if (StaftextBox.Text == "")
                {
                    query = "INSERT INTO Official_Info(StaffID,StaffName,Department,Designation,AgeExp,BloodGroup,JoiningDate,Nationality,Status ) VALUES(" + stfID + ", '" + StaffNatext.Text + "',  '" + DepartmentValue + "', '" + DesignationValue + "', " + Convert.ToInt32(EXPText.Text) + ", '" + BloodValue + "' , '" + joindateTimePicker.Value.ToString("yyyy/MM/dd") + "',  '" + NationaText.Text + "',  '" + StatusValue + "' )";
                }
                else
                {
                    query = "UPDATE Official_Info SET StaffName = '" + StaffNatext.Text + "' ,Department = '" + DepartmentValue + "', Designation = '" + DesignationValue + "',  AgeExp= '" + Convert.ToInt32(EXPText.Text) + "',BloodGroup = '" + BloodValue + "', JoiningDate = '" + joindateTimePicker.Value.ToString("yyyy/MM/dd") + "',Nationality = '" + NationaText.Text + "',Status = '" + StatusValue + "' WHERE StaffID = " + Convert.ToInt32(StaftextBox.Text);
                }

                if (DbAccess.ExecuteToDB(query))
                {
                    if (stfID != 0)
                    {
                        MessageBox.Show("Saved Successfully!!!");
                    }
                    else
                    {
                        MessageBox.Show("Updated Successfully!!!");
                    }
                }
                else
                {
                    MessageBox.Show("Failed To Save!!!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection Error!!!");
            }
            finally
            {
                Reset();
            }
        }