Beispiel #1
0
        //================== СПРАВОЧНИК ==================
        private void AddMemberButton_Click(object sender, EventArgs e)
        {
            var AddWindowForm = new AddBookMember();

            AddWindowForm.Text = "Добавление записи";

            var getrequest = "SELECT Id_Contact, Phone FROM Varpaev_ContactTable";
            var adapter    = new SqlDataAdapter(getrequest, connectionString);
            var InfoTable  = new DataTable();

            adapter.Fill(InfoTable);

            var dict = new Dictionary <int, string>();

            foreach (DataRow row in InfoTable.Rows)
            {
                dict.Add((int)row["Id_Contact"], row["Phone"].ToString());
            }
            AddWindowForm.PhoneData = dict;

            getrequest = "SELECT Id_Human, Last_Name FROM Varpaev_HumanTable";
            adapter    = new SqlDataAdapter(getrequest, connectionString);
            InfoTable  = new DataTable();
            adapter.Fill(InfoTable);

            dict = new Dictionary <int, string>();

            foreach (DataRow row in InfoTable.Rows)
            {
                dict.Add((int)row["Id_Human"], row["Last_Name"].ToString());
            }
            AddWindowForm.HumanData = dict;

            if (AddWindowForm.ShowDialog() == DialogResult.OK)
            {
                var conn = new SqlConnection(connectionString);
                conn.Open();
                string request = "INSERT INTO " + CrossTableName + "(Abonent_Id, Contact_Id)";
                request += " VALUES " + "('" + AddWindowForm.HumanInfo_Field + "', '"
                           + AddWindowForm.PhoneInfo_Field + "')";

                var com = new SqlCommand(request, conn);
                com.ExecuteNonQuery();
                conn.Close();
            }

            updateBookDGW();
        }
Beispiel #2
0
        private void EditBookMemberButton_Click(object sender, EventArgs e)
        {
            var form = new AddBookMember();

            var getReq  = "SELECT Id_Human, Last_Name, Name, Fathers_Name FROM" + "[" + AbonentTableName + "]";
            var Adapter = new SqlDataAdapter(getReq, connectionString);
            var dict    = new Dictionary <int, string>();
            var Table   = new DataTable();

            Adapter.Fill(Table);

            foreach (DataRow row in Table.Rows)
            {
                string setS = row["Last_Name"].ToString() + " " + row["Name"].ToString() + " "
                              + row["Fathers_Name"].ToString();
                dict.Add((int)row["Id_Human"], setS);
            }


            form.HumanData = dict;


            getReq  = "SELECT Id_Contact, Phone FROM" + "[" + ContactTableName + "]";
            Adapter = new SqlDataAdapter(getReq, connectionString);
            dict    = new Dictionary <int, string>();
            Table   = new DataTable();
            Adapter.Fill(Table);

            foreach (DataRow row in Table.Rows)
            {
                dict.Add((int)row["Id_Contact"], row["Phone"].ToString());
            }


            form.PhoneData = dict;

            DataGridViewSelectedRowCollection Row = BookDGW.SelectedRows;

            var mas       = BookDGW.SelectedRows;
            var Condidat  = mas[0].Cells["Id_Human"].FormattedValue.ToString();
            var Condidat2 = mas[0].Cells["Id_Contact"].FormattedValue.ToString();

            var conn = new SqlConnection(connectionString);

            conn.Open();
            string str  = "";
            var    req  = "SELECT Last_Name FROM " + AbonentTableName + " WHERE Id_Human = " + Condidat + "";
            var    com  = new SqlCommand(req, conn);
            var    last = com.ExecuteScalar();

            str += last + " ";
            req  = "SELECT Name FROM " + AbonentTableName + " WHERE Id_Human = " + Condidat + "";
            com  = new SqlCommand(req, conn);
            last = com.ExecuteScalar();
            str += last + " ";
            req  = "SELECT Fathers_Name FROM " + AbonentTableName + " WHERE Id_Human = " + Condidat + "";
            com  = new SqlCommand(req, conn);
            last = com.ExecuteScalar();
            str += last;
            form.HumanComboBox.Text = str;

            req  = "SELECT Phone FROM " + ContactTableName + " WHERE Id_Contact = " + Condidat2 + "";
            com  = new SqlCommand(req, conn);
            last = com.ExecuteScalar();
            form.PhoneComboBox.Text = last.ToString();

            conn.Close();

            if (form.ShowDialog() == DialogResult.OK)
            {
                conn = new SqlConnection(connectionString);
                conn.Open();

                var request = "UPDATE " + CrossTableName + " SET Contact_Id='" + form.PhoneInfo_Field +
                              "', " + "Abonent_Id ='" + form.HumanInfo_Field + "' WHERE Contact_Id=" + Condidat2 +
                              " AND Abonent_Id=" + Condidat;
                com = new SqlCommand(request, conn);
                com.ExecuteNonQuery();

                conn.Close();

                updateBookDGW();
            }
        }