Beispiel #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            ClientAddForm claForm = new ClientAddForm();
            if (claForm.ShowDialog() == DialogResult.OK)
            {
                bool status;
                string days = "";

                status = claForm.StatusComboBox.Text == "Да";

                foreach (Control c in claForm.Controls)
                {
                    CheckBox cb = c as CheckBox;
                    if (cb != null)
                    {
                        if (cb.Checked)
                            days += "1";
                        else
                            days += "0";
                    }
                }
                char[] arr = days.ToCharArray();
                Array.Reverse(arr);
                days = new String(arr);

                SqlConnection cn = new SqlConnection();
                cn = DBDevite.DBOpen();

                ClientDAL.InsertClient(ClientDAL.GetID(cn),
                                       claForm.NameTextBox.Text,
                                       claForm.AdressTextBox.Text,
                                       claForm.PhoneTextBox.Text,
                                       claForm.DateStartTimePicker.Value.Date,
                                       days,
                                       claForm.TimeStartComboBox.Text,
                                       claForm.TimeEndComboBox.Text,
                                       Convert.ToInt32(claForm.UserComboBox.SelectedValue),
                                       status, cn);

                DBDevite.DBClose(cn);

                GlobalVar.DictionaryClientsReload();
                GridReload();
            }
        }
Beispiel #2
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            int focused = Convert.ToInt32(dataGridViewClients[0,dataGridViewClients.CurrentRow.Index].Value);
            ClientAddForm claForm = new ClientAddForm();
            SqlConnection cn = new SqlConnection();
            try
            {
                string days;
                int i = 6;
                cn = DBDevite.DBOpen();
                DataSet dt = ClientDAL.GetFullRecord(focused, cn);

                claForm.NameTextBox.Text = dt.Tables[0].Rows[0]["Name"].ToString();
                claForm.AdressTextBox.Text = dt.Tables[0].Rows[0]["Adress"].ToString();
                claForm.PhoneTextBox.Text = dt.Tables[0].Rows[0]["Phone"].ToString();
                claForm.DateStartTimePicker.Value = Convert.ToDateTime(dt.Tables[0].Rows[0]["DateStart"].ToString());
                days = dt.Tables[0].Rows[0]["Days"].ToString();
                foreach (Control c in claForm.Controls)
                {
                    CheckBox cb = c as CheckBox;
                    if (cb != null)
                    {
                        cb.Checked = days[i] == '1';
                        i -= 1;
                    }
                }
                claForm.TimeStartComboBox.Text = dt.Tables[0].Rows[0]["TimeStart"].ToString();
                claForm.TimeEndComboBox.Text = dt.Tables[0].Rows[0]["TimeEnd"].ToString();
                claForm.UserComboBox.Text = dt.Tables[0].Rows[0]["Users"].ToString();
                if (dt.Tables[0].Rows[0]["ClientStatus"].ToString() == "True")
                    claForm.StatusComboBox.Text = "Да";
                else
                    claForm.StatusComboBox.Text = "Нет";

                if (claForm.ShowDialog() == DialogResult.OK)
                {
                    bool status;
                    days = "";

                    status = claForm.StatusComboBox.Text == "Да";

                    foreach (Control c in claForm.Controls)
                    {
                        CheckBox cb = c as CheckBox;
                        if (cb != null)
                        {
                            if (cb.Checked)
                                days += "1";
                            else
                                days += "0";
                        }
                    }
                    char[] arr = days.ToCharArray();
                    Array.Reverse(arr);
                    days = new String(arr);

                    ClientDAL.UpdateClient(focused,
                                           claForm.NameTextBox.Text,
                                           claForm.AdressTextBox.Text,
                                           claForm.PhoneTextBox.Text,
                                           claForm.DateStartTimePicker.Value.Date,
                                           days,
                                           claForm.TimeStartComboBox.Text,
                                           claForm.TimeEndComboBox.Text,
                                           Convert.ToInt32(claForm.UserComboBox.SelectedValue),
                                           status, cn);

                    GlobalVar.DictionaryClientsReload();
                    GridReload();
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBDevite.DBClose(cn);
            }
        }