private void PripremiPaging(Form forma, ref string tUpit, string iddok) { // POCETAK KODA VEZAN ZA PSGEING int intfrom = tUpit.ToUpper().IndexOf("FROM", StringComparison.OrdinalIgnoreCase); int intOrder = tUpit.ToUpper().IndexOf("ORDER", StringComparison.OrdinalIgnoreCase); if (intOrder > -1)// UPIT SADRZI ORDER BY { ((Bankom.frmChield)forma).intUkupno = db.ReturnInt(" select count(*) from " + tUpit.Substring(intfrom + 5, intOrder - intfrom - 5), 0); } else { ((Bankom.frmChield)forma).intUkupno = db.ReturnInt(" select count(*) from " + tUpit.Substring(intfrom + 5), 0); } ((Bankom.frmChield)forma).toolStripTextBroj.Text = iddok; ((Bankom.frmChield)forma).statusStrip1.Visible = true; string strstart = ""; int pageno = 0; if (((Bankom.frmChield)forma).intUkupno > 0) { if (((Bankom.frmChield)forma).BrRedova > 0) { pageno = ((Bankom.frmChield)forma).intUkupno / ((Bankom.frmChield)forma).BrRedova; } } if (pageno * ((Bankom.frmChield)forma).BrRedova < ((Bankom.frmChield)forma).intUkupno) { pageno = pageno + 1; } string strFind = ""; strFind = ((Bankom.frmChield)forma).toolStripTextFind.Text; ((Bankom.frmChield)forma).ToolStripLblPos.Text = Convert.ToString(pageno); ((Bankom.frmChield)forma).toolStripTexIme.Text = ((Bankom.frmChield)forma).Controls["limedok"].Text; if (((Bankom.frmChield)forma).intStart < 0) { ((Bankom.frmChield)forma).intStart = 0; } if (((Bankom.frmChield)forma).intUkupno > 0 && ((Bankom.frmChield)forma).intStart >= ((Bankom.frmChield)forma).intUkupno) { ((Bankom.frmChield)forma).intStart = ((Bankom.frmChield)forma).intUkupno - ((Bankom.frmChield)forma).BrRedova; strstart = Convert.ToString(((Bankom.frmChield)forma).intStart); } if (((Bankom.frmChield)forma).intUkupno > ((Bankom.frmChield)forma).BrRedova) { strstart = ""; frmChield activeChild1 = (frmChield)forma.ActiveMdiChild; if (activeChild1 != null) // da li se nalazimo na forma ako je odgovor DA nije null radi se o PAGING-u { strFind = activeChild1.toolStripTextFind.Text.ToString(); strstart = activeChild1.ToolStripTextPos.Text.ToString(); ((Bankom.frmChield)activeChild1).ToolStripLblPos.Text = Convert.ToString(((Bankom.frmChield)activeChild1).intUkupno); if (((Bankom.frmChield)activeChild1).intUkupno > 0 && ((Bankom.frmChield)activeChild1).intStart >= ((Bankom.frmChield)activeChild1).intUkupno) { ((Bankom.frmChield)activeChild1).intStart = ((Bankom.frmChield)activeChild1).intUkupno - ((Bankom.frmChield)forma).BrRedova; strstart = Convert.ToString(((Bankom.frmChield)activeChild1).intStart); } } else { strFind = ((Bankom.frmChield)forma).toolStripTextFind.Text.ToString(); strstart = Convert.ToString(((Bankom.frmChield)forma).intStart); ((Bankom.frmChield)forma).ToolStripLblPos.Text = Convert.ToString(pageno); if (((Bankom.frmChield)forma).intUkupno > 0 && ((Bankom.frmChield)forma).intStart >= ((Bankom.frmChield)forma).intUkupno) { ((Bankom.frmChield)forma).intStart = ((Bankom.frmChield)forma).intUkupno - ((Bankom.frmChield)forma).BrRedova; strstart = Convert.ToString(((Bankom.frmChield)forma).intStart); } } switch (strFind) { case "": case null: if (intOrder > -1) { tUpit += " OFFSET " + strstart + " ROWS FETCH NEXT " + ((Bankom.frmChield)forma).BrRedova + " ROWS ONLY;"; } Console.WriteLine(tUpit); break; default: if (intOrder > -1) { string[] separating = new[] { "<", ">" }; string[] words = strFind.Trim().Split(separating, System.StringSplitOptions.RemoveEmptyEntries); strFind = ""; foreach (var word in words) { if (word.Trim() != "") { strFind += " and " + word.Replace(":", " like '%") + "%'"; } } tUpit = tUpit.Replace("order", strFind + " order"); intfrom = tUpit.IndexOf("from", StringComparison.OrdinalIgnoreCase); intOrder = tUpit.IndexOf("order", StringComparison.OrdinalIgnoreCase); if (activeChild1 != null) { DataTable tu = db.ReturnDataTable(tUpit); int intukupno = tu.Rows.Count; activeChild1.intUkupno = intukupno; if (((Bankom.frmChield)forma).BrRedova > 0) { float broj = intukupno / ((Bankom.frmChield)forma).BrRedova; activeChild1.ToolStripLblPos.Text = Convert.ToString(intukupno / ((Bankom.frmChield)forma).BrRedova); } } DataTable tu1 = db.ReturnDataTable(tUpit); int intukupno1 = tu1.Rows.Count; ((Bankom.frmChield)forma).ToolStripLblPos.Text = Convert.ToString(intukupno1 / ((Bankom.frmChield)forma).BrRedova); tUpit += " OFFSET " + strstart + " ROWS FETCH NEXT " + ((Bankom.frmChield)forma).BrRedova + " ROWS ONLY;"; } break; } } }
// public void refreshDokumentGrid(Form forma, string dokument, string iddok, string mUpit, string DokumentJe) { form1 = forma; string tUpit; string tIme; string tud; string KojiSegment; if (dokument != "Dokumenta") { } // string xxx = ((Bankom.frmChield)form1).imedokumenta; string ss = " SELECT TUD, MaxHeight, Levo, Vrh, Width, height, Upit, Ime " + " FROM dbo.Upiti " + " WHERE(NazivDokumenta = N'" + dokument + "' AND Ime Like'GgRr%') " + " AND(TUD <> 0) ORDER By TUD"; DataTable t = db.ReturnDataTable(ss); if (t.Rows.Count > 0) { for (int i = 0; i <= t.Rows.Count - 1; i++) { tIme = t.Rows[i]["Ime"].ToString(); KojiSegment = tIme.Substring(4, tIme.Length - 4); tud = t.Rows[i]["TUD"].ToString(); //mUpit= t.Rows[i]["Upit"].ToString(); if (!(form1.Controls.Find(tIme, true).FirstOrDefault() is DataGridView dv)) { MessageBox.Show("Greska ne postoji grid"); } else { dv.Visible = true; //if (DokumentJe == "S") if (mUpit.Trim() != "") { tUpit = mUpit; tUpit = tUpit.Replace("SELECT DISTINCT", "SELECT "); //SELECT TOP (200) } else { tUpit = t.Rows[i]["Upit"].ToString(); tUpit = CreateQuery(tUpit, KojiSegment, iddok, dokument, DokumentJe); } if (DokumentJe == "D" && tud == "1") { tUpit = tUpit + " Order by iid DESC "; } string RbPolje = "ID_GgRr" + (KojiSegment).Trim(); int intfrom = tUpit.IndexOf("from", StringComparison.OrdinalIgnoreCase);; int intOrder = tUpit.IndexOf("order", StringComparison.OrdinalIgnoreCase); int intstart = 0; if (form1.Text.ToString().IndexOf("(") == -1) { int intUkupno = ((Bankom.frmChield)form1).intUkupno; if (iddok != "1") { Program.pocetak = 0; if (intOrder > intfrom) { ((Bankom.frmChield)form1).intUkupno = db.ReturnInt(" select count(*) from " + tUpit.Substring(intfrom + 5, intOrder - intfrom - 5), 0); ((Bankom.frmChield)form1).ToolStripLblPos.Text = Convert.ToString(((Bankom.frmChield)form1).intUkupno / 25); switch (dokument) { case "Dokumenta": DataTable tbb = db.ReturnDataTable("select top 1 naziv from DokumentaStablo where ID_DokumentaStablo=" + iddok); ((Bankom.frmChield)form1).toolStripTexIme.Text = Convert.ToString(tbb.Rows[0][0]); break; case "Artikli": DataTable tbbart = db.ReturnDataTable("select top 1 * from ArtikliStablo where ID_ArtikliStablo=" + iddok); ((Bankom.frmChield)form1).toolStripTexIme.Text = Convert.ToString(tbbart.Rows[0][0]); break; default: break; } ((Bankom.frmChield)form1).toolStripTextBroj.Text = iddok; } else { intstart = ((Bankom.frmChield)form1).intStart; // PROVERI DA LI TREBA ((Bankom.frmChield)form1).intUkupno = db.ReturnInt(" select count(*) from " + tUpit.Substring(intfrom + 5), 0); } } } if (intOrder > -1) { tUpit += " OFFSET " + Program.pocetak.ToString() + " ROWS FETCH NEXT 25 ROWS ONLY;"; } if (mUpit != "") { ((Bankom.frmChield)form1).Controls["statusStrip1"].Visible = true; } DataTable tg = db.ReturnDataTable(tUpit); if (tg.Rows.Count > 0) { if (DokumentJe == "D") { for (int k = 0; k <= tg.Rows.Count - 1; k++) { //tg.Rows[k][RbPolje].Value = k; } } dv.DataSource = tg; dv.Visible = true; } setingWidthOfColumns(dokument, dv, tud); dv.Visible = true; } }