| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Data.SqlClient;
- namespace СУБД_Агентство
- {
- public partial class FormPotrebRielter : Form
- {
- public FormPotrebRielter()
- {
- InitializeComponent();
- }
- // процент от продажи, процент от покупки
- double procprodazha, procpokupka;
- private void FormPotrebRielter_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'dbAgentstvoDataSet1.predlozhenie' table. You can move, or remove it, as needed.
- this.predlozhenieTableAdapter.Fill(this.dbAgentstvoDataSet1.predlozhenie);
- // TODO: This line of code loads data into the 'dbAgentstvoDataSet1.Potrebnost' table. You can move, or remove it, as needed.
- this.potrebnostTableAdapter.Fill(this.dbAgentstvoDataSet1.Potrebnost);
- // TODO: This line of code loads data into the 'dbAgentstvoDataSet1.Users' table. You can move, or remove it, as needed.
- this.usersTableAdapter.Fill(this.dbAgentstvoDataSet1.Users);
- // чтобы не отображались предложения для пустой таблицы с потребностями
- if (bsPotrebnost.Count == 0)
- bsPredlozheniya.Filter = "'False'";
- // открыть файл для чтения
- StreamReader sr = new StreamReader("data.txt");
- string t = sr.ReadLine(); // прочитать первую строку с макс. кол-вом клиентов
- procprodazha = Convert.ToDouble(sr.ReadLine()); // процент от продажи
- procpokupka = Convert.ToDouble(sr.ReadLine()); // процент от покупки
- sr.Close(); // закрыть файл
- }
- private void btnSdelka_Click(object sender, EventArgs e)
- {
- // код потребности и предложения, участвующих в сделке
- string idpotreb = dgvPotreb.CurrentRow.Cells[8].Value.ToString();
- string idpredl = dgvPredl.CurrentRow.Cells[5].Value.ToString();
- string famrielterpok = lblFamRielterPok.Text; // риелтер покупателя
- // id покупателя
- string idpok = dgvPotreb.CurrentRow.Cells[10].Value.ToString();
- // id риелтера продавца
- string idrielterprod = dgvPredl.CurrentRow.Cells[7].Value.ToString();
-
- // отфильтровать пользователя - покупателя
- bsUsersFam.Filter = "idusers = " + idpok;
- string fampok = lblFam.Text; // прочитать фамилию покупателя
- // отфильтровать пользователя - риелтера продавца
- bsUsersFam.Filter = "idusers = " + idrielterprod;
- string famrielterprod = lblFam.Text; // прочитать фамилию риелтера продавца
-
- // подключение к базе данных
- SqlConnection con = new SqlConnection(Form1.txtcon);
- con.Open(); // открыть подключение к базе данных
- // SQL-запрос для добавления записи
- string t = String.Format(@"
- insert into Sdelka
- (idpotrebnost, idpredlozhenie, datesdelka)
- values ({0}, {1}, '{2}')", idpotreb, idpredl, DateTime.Now.ToString("dd.MM.yyyy"));
- // установить формат даты на сервере
- SqlCommand query2 = new SqlCommand("set dateformat dmy", con);
- query2.ExecuteNonQuery();
- // Добавить в таблицу Сделка новую запись
- SqlCommand query1 = new SqlCommand(t, con);
- query1.ExecuteNonQuery();
- con.Close(); // закрыть подключение к базе данных
- // цена проданного объекта недвижимости
- double sum = Convert.ToDouble(dgvPredl.CurrentRow.Cells[4].Value);
- // комиссия для риелетра покупателя
- double sumrielterpok = sum * procpokupka / 100;
- // комиссия для риелетра продавца
- double sumrielterprod = sum * procprodazha / 100;
- sum += sumrielterpok + sumrielterprod;
- // предложение и потребность, участвующие в сделке завершены
- dgvPredl.CurrentRow.Cells[6].Value = true;
- bsPredlozheniya.EndEdit();
- predlozhenieTableAdapter.Update(this.dbAgentstvoDataSet1.predlozhenie);
- // сначала обязательно сохранить изменения в таблице Предложения, а только
- // потом в таблице Потребности. Если сделать наоборот, то при сохранении
- // потребностей в таблице Предложения исчезнет выделенная строка
- dgvPotreb.CurrentRow.Cells[9].Value = true;
- bsPotrebnost.EndEdit();
- potrebnostTableAdapter.Update(this.dbAgentstvoDataSet1.Potrebnost);
- // чтобы не отображались предложения для пустой таблицы с потребностями
- if (bsPotrebnost.Count == 0)
- bsPredlozheniya.Filter = "'False'";
- MessageBox.Show(@"Сделка совершена.
- Покупатель " + fampok + " должен заплатить: " + sum +
- "\nРиелтер покупателя " + famrielterpok + " получает: " + sumrielterpok +
- "\nРиелтер продавца " + famrielterprod + " получает: " + sumrielterprod);
- }
- private void dataGridView1_SelectionChanged(object sender, EventArgs e)
- {
- // если нет выделенной потребности, то выйти из процедуры
- if (dgvPotreb.CurrentRow == null) return;
- // прочитать из DataGridView параметры выделенной потребности
- int minplosh = Convert.ToInt32(dgvPotreb.CurrentRow.Cells[0].Value);
- int maxplosh = Convert.ToInt32(dgvPotreb.CurrentRow.Cells[1].Value);
- int minetazh = Convert.ToInt32(dgvPotreb.CurrentRow.Cells[2].Value);
- int maxetazh = Convert.ToInt32(dgvPotreb.CurrentRow.Cells[3].Value);
- int minkomnat = Convert.ToInt32(dgvPotreb.CurrentRow.Cells[4].Value);
- int maxkomnat = Convert.ToInt32(dgvPotreb.CurrentRow.Cells[5].Value);
- double mincena = Convert.ToDouble(dgvPotreb.CurrentRow.Cells[6].Value);
- double maxcena = Convert.ToDouble(dgvPotreb.CurrentRow.Cells[7].Value);
- string t = String.Format("plosh >= {0} and plosh <= {1} and etazh >= {2} and etazh <= {3} and komnat >= {4} and komnat <= {5} and cena >= {6} and cena <= {7} and zaversheno = 'False'", minplosh, maxplosh, minetazh, maxetazh, minkomnat, maxkomnat, mincena, maxcena);
-
- // отфильтровать предложения, подходящие для реализации потребности
- bsPredlozheniya.Filter = t;
- }
- }
- }
|