| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Data.SqlClient;
|
|---|
| 6 | using System.Drawing;
|
|---|
| 7 | using System.Text;
|
|---|
| 8 | using System.Windows.Forms;
|
|---|
| 9 |
|
|---|
| 10 | namespace Baza_Reklam
|
|---|
| 11 | {
|
|---|
| 12 | public partial class ZestawienieZamowienForm : Form
|
|---|
| 13 | {
|
|---|
| 14 | string query = "SELECT top 2000 * from VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE ";
|
|---|
| 15 |
|
|---|
| 16 | private static ZestawienieZamowienForm form;
|
|---|
| 17 | private SqlCommand command;
|
|---|
| 18 | private SqlDataAdapter sqlDataAdapter;
|
|---|
| 19 |
|
|---|
| 20 | private bool commandExecuted = false;
|
|---|
| 21 |
|
|---|
| 22 | public static ZestawienieZamowienForm getZestawienieZamowienForm(MDIBazaReklam parent)
|
|---|
| 23 | {
|
|---|
| 24 | if (form == null){
|
|---|
| 25 | form = new ZestawienieZamowienForm(parent);
|
|---|
| 26 | }
|
|---|
| 27 | return form;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | private ZestawienieZamowienForm(MDIBazaReklam parent)
|
|---|
| 31 | {
|
|---|
| 32 | InitializeComponent();
|
|---|
| 33 |
|
|---|
| 34 | this.MdiParent = parent;
|
|---|
| 35 |
|
|---|
| 36 | //podmiana connstringa
|
|---|
| 37 | this.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWETableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 38 | this.reklamyZestawienieTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 39 |
|
|---|
| 40 | //obiekty wykorzytywane przy wyszukiwaniu
|
|---|
| 41 | SqlConnection conn = new SqlConnection(ConnString.getConnString().Value);
|
|---|
| 42 |
|
|---|
| 43 | command = new SqlCommand();
|
|---|
| 44 | command.CommandType = CommandType.Text;
|
|---|
| 45 | command.Connection = conn;
|
|---|
| 46 |
|
|---|
| 47 | this.sqlDataAdapter = new SqlDataAdapter();
|
|---|
| 48 |
|
|---|
| 49 | //generuje piersze wêz³y w drzewie
|
|---|
| 50 | generateNodes();
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | private void FacturesForm_Load(object sender, EventArgs e)
|
|---|
| 54 | {
|
|---|
| 55 | this.WindowState = FormWindowState.Maximized;
|
|---|
| 56 | command.CommandText = this.query;
|
|---|
| 57 | sqlDataAdapter.SelectCommand = command;
|
|---|
| 58 |
|
|---|
| 59 | DBBindings.bindujAgencje(agencjaToolStripComboBox);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | private void generateNodes()
|
|---|
| 63 | {
|
|---|
| 64 | TreeNode node;
|
|---|
| 65 |
|
|---|
| 66 | node = new TreeNode("Biura");
|
|---|
| 67 | node.Nodes.Add(new TreeNode());
|
|---|
| 68 | node.Name = "Biura";
|
|---|
| 69 | treeView1.Nodes.Add(node);
|
|---|
| 70 |
|
|---|
| 71 | command.Connection.Close();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
|
|---|
| 75 | {
|
|---|
| 76 | if (e.Node != null)
|
|---|
| 77 | {
|
|---|
| 78 | command.CommandText = query;
|
|---|
| 79 | command.Parameters.Clear();
|
|---|
| 80 |
|
|---|
| 81 | switch (e.Node.Level)
|
|---|
| 82 | {
|
|---|
| 83 | case 0:
|
|---|
| 84 | break;
|
|---|
| 85 | case 1:
|
|---|
| 86 | break;
|
|---|
| 87 | case 2:
|
|---|
| 88 | break;
|
|---|
| 89 | case 3:
|
|---|
| 90 | switch (e.Node.Parent.Parent.Parent.Name)
|
|---|
| 91 | {
|
|---|
| 92 | case "Biura":
|
|---|
| 93 |
|
|---|
| 94 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 95 |
|
|---|
| 96 | rEKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE.Clear();
|
|---|
| 97 | command.CommandText += " where agent=@agent";
|
|---|
| 98 | command.Parameters.AddWithValue("@agent", e.Node.Name);
|
|---|
| 99 | sqlDataAdapter.Fill(this.rEKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE);
|
|---|
| 100 | commandExecuted = true;
|
|---|
| 101 | fakturyDataGridView.Refresh();
|
|---|
| 102 |
|
|---|
| 103 | this.Cursor = Cursors.Default;
|
|---|
| 104 |
|
|---|
| 105 | break;
|
|---|
| 106 | default:
|
|---|
| 107 | break;
|
|---|
| 108 | }
|
|---|
| 109 | break;
|
|---|
| 110 | case 4:
|
|---|
| 111 | break;
|
|---|
| 112 | default:
|
|---|
| 113 | break;
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
|
|---|
| 119 | {
|
|---|
| 120 | TreeNode node;
|
|---|
| 121 | SqlDataReader reader;
|
|---|
| 122 |
|
|---|
| 123 | if (e.Node != null)
|
|---|
| 124 | {
|
|---|
| 125 | switch (e.Node.Level)
|
|---|
| 126 | {
|
|---|
| 127 | case 0:
|
|---|
| 128 | switch (e.Node.Name)
|
|---|
| 129 | {
|
|---|
| 130 | case "Biura":
|
|---|
| 131 | DBBindings.dodajAgencjeDoWezla(e.Node);
|
|---|
| 132 | break;
|
|---|
| 133 | }
|
|---|
| 134 | break;
|
|---|
| 135 | case 1:
|
|---|
| 136 | switch (e.Node.Parent.Name)
|
|---|
| 137 | {
|
|---|
| 138 | case "Biura":
|
|---|
| 139 | e.Node.Nodes.Clear();
|
|---|
| 140 |
|
|---|
| 141 | node = new TreeNode("Agenci");
|
|---|
| 142 | node.Name = "Agenci";
|
|---|
| 143 | e.Node.Nodes.Add(node);
|
|---|
| 144 | DBBindings.dodajAgentowDoWezla(node, e.Node.Name);
|
|---|
| 145 | break;
|
|---|
| 146 | }
|
|---|
| 147 | break;
|
|---|
| 148 | default:
|
|---|
| 149 | break;
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | private void wyszukajToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 155 | {
|
|---|
| 156 | wyszukajToolStrip.Visible = wyszukajToolStrip.Visible ? false : true;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | private void fakturyDataGridView_Leave(object sender, EventArgs e)
|
|---|
| 161 | {
|
|---|
| 162 | fakturyDataGridView.EndEdit();
|
|---|
| 163 | }
|
|---|
| 164 | private void zestawienieFakturBindingSource_ListChanged(object sender, ListChangedEventArgs e)
|
|---|
| 165 | {
|
|---|
| 166 |
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | private void toolStripButton1_Click(object sender, EventArgs e)
|
|---|
| 170 | {
|
|---|
| 171 | PrintDGV.Print_DataGridView(fakturyDataGridView,50);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | private void wyczyscPolaToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 175 | {
|
|---|
| 176 | nrZamToolStripTextBox.Text = string.Empty;
|
|---|
| 177 | agencjaToolStripComboBox.SelectedIndex = -1;
|
|---|
| 178 | kodKlientaToolStripTextBox.Text = string.Empty;
|
|---|
| 179 | rokToolStripTextBox.Text = string.Empty;
|
|---|
| 180 | kodRozliczeniowyToolStripTextBox.Text = string.Empty;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | /// <summary>
|
|---|
| 184 | /// Przechodzi do okna KLIENCI i wywietla dane klienta zwi¹zanego z faktur¹.
|
|---|
| 185 | /// </summary>
|
|---|
| 186 | private void klientToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 187 | {
|
|---|
| 188 |
|
|---|
| 189 | if (VIEW_ZESTAWIENIE_ZAMOWIEN_NOWEBindingSource.Current != null)
|
|---|
| 190 | {
|
|---|
| 191 | DataRowView row = (DataRowView)VIEW_ZESTAWIENIE_ZAMOWIEN_NOWEBindingSource.Current;
|
|---|
| 192 |
|
|---|
| 193 | int custID = Convert.ToInt32(row["idKlienta"]);
|
|---|
| 194 |
|
|---|
| 195 | ClientsForm.getClientsForm((MDIBazaReklam)this.MdiParent).pokazKlienta(custID);
|
|---|
| 196 |
|
|---|
| 197 | this.Hide();
|
|---|
| 198 |
|
|---|
| 199 | ClientsForm.getClientsForm((MDIBazaReklam)this.MdiParent).Show();
|
|---|
| 200 |
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | private void FacturesForm_Shown(object sender, EventArgs e)
|
|---|
| 205 | {
|
|---|
| 206 | rokToolStripTextBox.Text = DateTime.Today.Year.ToString();
|
|---|
| 207 |
|
|---|
| 208 | if (User.getUser().St_kierownik)
|
|---|
| 209 | {
|
|---|
| 210 | agencjaToolStripComboBox.Text = User.getUser().SymbolAgencji;
|
|---|
| 211 | }
|
|---|
| 212 | else if (User.getUser().St_handlowiec | User.getUser().St_subhandlowiec)
|
|---|
| 213 | {
|
|---|
| 214 | kodRozliczeniowyToolStripTextBox.Text = User.getUser().Kod_agenta;
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | private void excelToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 219 | {
|
|---|
| 220 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 221 |
|
|---|
| 222 | ExcelHandler ex = new ExcelHandler();
|
|---|
| 223 | ex.exportToExcel(fakturyDataGridView);
|
|---|
| 224 |
|
|---|
| 225 | this.Cursor = Cursors.Default;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | private void VIEW_ZESTAWIENIE_ZAMOWIEN_NOWEBindingSource_CurrentChanged(object sender, EventArgs e)
|
|---|
| 229 | {
|
|---|
| 230 | DataRowView row = (DataRowView)VIEW_ZESTAWIENIE_ZAMOWIEN_NOWEBindingSource.Current;
|
|---|
| 231 | REKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWERow zam =
|
|---|
| 232 | (REKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWERow)row.Row;
|
|---|
| 233 |
|
|---|
| 234 | this.reklamyZestawienieTableAdapter.FillByIdZamowienia(
|
|---|
| 235 | this.rEKLAMADataSet.ReklamyZestawienie,zam.idZamowienia);
|
|---|
| 236 |
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | private void zamowieniaToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 240 | {
|
|---|
| 241 | if (VIEW_ZESTAWIENIE_ZAMOWIEN_NOWEBindingSource.Current != null)
|
|---|
| 242 | {
|
|---|
| 243 | DataRowView row = (DataRowView)VIEW_ZESTAWIENIE_ZAMOWIEN_NOWEBindingSource.Current;
|
|---|
| 244 |
|
|---|
| 245 | REKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWERow zam =
|
|---|
| 246 | (REKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWERow)row.Row;
|
|---|
| 247 |
|
|---|
| 248 | ZamowieniaForm zf = new ZamowieniaForm(zam.idKlienta,zam.idZamowienia);
|
|---|
| 249 | zf.ShowDialog();
|
|---|
| 250 | }
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | private void odswiezToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 254 | {
|
|---|
| 255 | if (commandExecuted)
|
|---|
| 256 | {
|
|---|
| 257 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 258 |
|
|---|
| 259 | rEKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE.Clear();
|
|---|
| 260 | sqlDataAdapter.Fill(this.rEKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE);
|
|---|
| 261 | fakturyDataGridView.Refresh();
|
|---|
| 262 |
|
|---|
| 263 | this.Cursor = Cursors.Default;
|
|---|
| 264 | }
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | private void zamToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 268 | {
|
|---|
| 269 |
|
|---|
| 270 | if (reklamyZestawienieBindingSource.Current != null)
|
|---|
| 271 | {
|
|---|
| 272 | DataRowView row = (DataRowView)reklamyZestawienieBindingSource.Current;
|
|---|
| 273 |
|
|---|
| 274 | if (row["reklamaId"] != DBNull.Value)
|
|---|
| 275 | {
|
|---|
| 276 | int idRek = Convert.ToInt32(row["reklamaId"]);
|
|---|
| 277 |
|
|---|
| 278 | OrderDetails.getOrderDetails().pokazSzczegolyZamowienia(idRek);
|
|---|
| 279 | OrderDetails.getOrderDetails().ShowDialog();
|
|---|
| 280 | }
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | private void szukajToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 286 | {
|
|---|
| 287 | command.CommandText = query;
|
|---|
| 288 |
|
|---|
| 289 | this.rEKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE.Clear();
|
|---|
| 290 |
|
|---|
| 291 | command.CommandText += " where 1=1 ";
|
|---|
| 292 |
|
|---|
| 293 | command.Parameters.Clear();
|
|---|
| 294 |
|
|---|
| 295 | if (nrZamToolStripTextBox.Text.Trim() != "")
|
|---|
| 296 | {
|
|---|
| 297 | int i;
|
|---|
| 298 | if (!Int32.TryParse(nrZamToolStripTextBox.Text.Trim(), out i))
|
|---|
| 299 | {
|
|---|
| 300 | MessageBox.Show("Podaj prawid³owy numer zamówienia.");
|
|---|
| 301 | return;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | command.CommandText += " AND NR=@nr";
|
|---|
| 305 | command.Parameters.AddWithValue("@nr", nrZamToolStripTextBox.Text.Trim());
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | if (rokToolStripTextBox.Text.Trim() != "")
|
|---|
| 309 | {
|
|---|
| 310 | int i;
|
|---|
| 311 | if (!Int32.TryParse(rokToolStripTextBox.Text.Trim(), out i))
|
|---|
| 312 | {
|
|---|
| 313 | MessageBox.Show("Podaj prawid³owy rok.");
|
|---|
| 314 | return;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | command.CommandText += " AND rokZamowienia=@rok";
|
|---|
| 318 | command.Parameters.AddWithValue("@rok", rokToolStripTextBox.Text.Trim());
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | if (kodRozliczeniowyToolStripTextBox.Text.Trim() != "")
|
|---|
| 322 | {
|
|---|
| 323 | command.CommandText += " AND kodAgenta like '%' + @kod + '%'";
|
|---|
| 324 | command.Parameters.AddWithValue("@kod", kodRozliczeniowyToolStripTextBox.Text.Trim());
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | if (kodKlientaToolStripTextBox.Text.Trim() != "")
|
|---|
| 328 | {
|
|---|
| 329 | command.CommandText += " AND kodKlienta like '%' + @kodKlienta + '%'";
|
|---|
| 330 | command.Parameters.AddWithValue("@kodKlienta", kodKlientaToolStripTextBox.Text.Trim());
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | if (agencjaToolStripComboBox.Text.Trim() != "")
|
|---|
| 334 | {
|
|---|
| 335 | command.CommandText += " AND Agencja=@agencja";
|
|---|
| 336 | command.Parameters.AddWithValue("@agencja", agencjaToolStripComboBox.Text.Trim());
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | sqlDataAdapter.SelectCommand = command;
|
|---|
| 340 |
|
|---|
| 341 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 342 |
|
|---|
| 343 | try
|
|---|
| 344 | {
|
|---|
| 345 | int t = sqlDataAdapter.Fill(this.rEKLAMADataSet.VIEW_ZESTAWIENIE_ZAMOWIEN_NOWE);
|
|---|
| 346 | commandExecuted = true;
|
|---|
| 347 | }
|
|---|
| 348 | catch (Exception e1)
|
|---|
| 349 | {
|
|---|
| 350 | MessageBox.Show(e1.Message);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | treeView1.CollapseAll();
|
|---|
| 354 | treeView1.SelectedNode = null;
|
|---|
| 355 |
|
|---|
| 356 | this.Cursor = Cursors.Default;
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | }
|
|---|
| 360 | } |
|---|