How can I use last-of in a QUERY-PREPARE()? - openedge
I made a huge code and it was taking a very long time to process. Following suggestions here, I made it shorter and better and now it's running much faster. However, I noticed I should be getting a sum of the values whereas I'm just getting the values. I tried using ACCUMULATE TOTAL, but it didn't work because the LAST-OF can only be used with a BREAK BY and my break by is inside the QUERY-PREPARE().
How can I get the sum of the following values?
doc-fiscal.vl-cont-doc
doc-fiscal.vl-bicms
doc-fiscal.vl-icms
doc-fiscal.vl-icmsou
doc-fiscal.vl-ipiou
doc-fiscal.vl-ipi
Bellow is the code I'm using, which is working almost perfectly.
//Query
cQuery = "FOR EACH doc-fiscal WHERE doc-fiscal.dt-docto >= " + QUOTER(pd-data-1) + " AND doc-fiscal.dt-docto <= " + QUOTER(pd-data-2) + " AND (doc-fiscal.cod-observa <> 4 OR doc-fiscal.tipo-nat <> 3) AND doc-fiscal.cd-situacao <> 06 AND doc-fiscal.cd-situacao <> 22".
cQuery = cQuery + semCodEmitente + comCodEmitente + CheckBoxindSitDoc.
cQuery = cQuery + ", EACH natur-oper USE-INDEX natureza WHERE doc-fiscal.nat-operacao = natur-oper.nat-operacao" + modeloEletronico + tipoEntrada + natOper.
cQuery = cQuery + " BREAK BY doc-fiscal.dt-docto BY doc-fiscal.nr-doc-fis ".
QUERY qRelatorio:QUERY-PREPARE(cQuery).
QUERY qRelatorio:QUERY-OPEN().
GET FIRST qRelatorio.
DEF VAR soma-vl-cont-doc AS DECIMAL.
DO WHILE AVAILABLE doc-fiscal:
soma-vl-cont-doc = soma-vl-cont-doc + doc-fiscal.vl-cont-doc.
IF LAST-OF(doc-fiscal.nr-doc-fis) THEN DO:
CREATE tt-relatorio.
ASSIGN
tt-relatorio.nr-doc-fis = doc-fiscal.nr-doc-fis
tt-relatorio.serie = doc-fiscal.serie
tt-relatorio.char-2 = SUBSTRING(doc-fiscal.char-2,155,44, "CHAR")
tt-relatorio.cod-model-nf-eletro = natur-oper.cod-model-nf-eletro
tt-relatorio.tipo = natur-oper.tipo
tt-relatorio.cod-estabel = doc-fiscal.cod-estabel
tt-relatorio.cod-emitente = doc-fiscal.cod-emitente
tt-relatorio.nome-ab-emi = doc-fiscal.nome-ab-emi
tt-relatorio.cgc = doc-fiscal.cgc
tt-relatorio.dt-emis-doc = doc-fiscal.dt-emis-doc
tt-relatorio.dt-docto = doc-fiscal.dt-docto
tt-relatorio.ind-sit-doc = doc-fiscal.ind-sit-doc
tt-relatorio.vl-cont-doc = doc-fiscal.vl-cont-doc
tt-relatorio.vl-bicms = doc-fiscal.vl-bicms
tt-relatorio.vl-icms = doc-fiscal.vl-icms
tt-relatorio.vl-icmsou = doc-fiscal.vl-icmsou
tt-relatorio.vl-ipiou = doc-fiscal.vl-ipiou
tt-relatorio.vl-ipi = doc-fiscal.vl-ipi
tt-relatorio.imp-nota = natur-oper.imp-nota.
GET NEXT qRelatorio.
END.
END.
QUERY qRelatorio:QUERY-CLOSE().
Thanks for the help and sorry for being such a newbie. I hope my question can help other people.
I managed to do it.
I used LAST-OF() METHOD. My code became the following.
DEF VAR soma-vl-cont-doc AS DECIMAL. //INICIO DAS SOMAS
DEF VAR soma-vl-bicms AS DECIMAL.
DEF VAR soma-vl-icms AS DECIMAL.
DEF VAR soma-vl-icmsou AS DECIMAL.
DEF VAR soma-vl-ipiou AS DECIMAL.
DEF VAR soma-vl-ipi AS DECIMAL.
DO WHILE AVAILABLE doc-fiscal:
soma-vl-cont-doc = soma-vl-cont-doc + doc-fiscal.vl-cont-doc.
soma-vl-bicms = soma-vl-bicms + doc-fiscal.vl-bicms.
soma-vl-icms = soma-vl-icms + doc-fiscal.vl-icms.
soma-vl-icmsou = soma-vl-icmsou + doc-fiscal.vl-icmsou.
soma-vl-ipiou = soma-vl-ipiou + doc-fiscal.vl-ipiou.
soma-vl-ipi = soma-vl-ipi + doc-fiscal.vl-ipi.
IF QUERY qRelatorio:LAST-OF(2) THEN DO:
CREATE tt-relatorio.
ASSIGN
tt-relatorio.nr-doc-fis = doc-fiscal.nr-doc-fis
tt-relatorio.serie = doc-fiscal.serie
tt-relatorio.char-2 = SUBSTRING(doc-fiscal.char-2,155,44, "CHAR")
tt-relatorio.cod-model-nf-eletro = natur-oper.cod-model-nf-eletro
tt-relatorio.tipo = natur-oper.tipo
tt-relatorio.cod-estabel = doc-fiscal.cod-estabel
tt-relatorio.cod-emitente = doc-fiscal.cod-emitente
tt-relatorio.nome-ab-emi = doc-fiscal.nome-ab-emi
tt-relatorio.cgc = doc-fiscal.cgc
tt-relatorio.dt-emis-doc = doc-fiscal.dt-emis-doc
tt-relatorio.dt-docto = doc-fiscal.dt-docto
tt-relatorio.ind-sit-doc = doc-fiscal.ind-sit-doc
tt-relatorio.vl-cont-doc = soma-vl-cont-doc
tt-relatorio.vl-bicms = soma-vl-bicms
tt-relatorio.vl-icms = soma-vl-icms
tt-relatorio.vl-icmsou = soma-vl-icmsou
tt-relatorio.vl-ipiou = soma-vl-ipiou
tt-relatorio.vl-ipi = soma-vl-ipi
//tt-relatorio.idi-sit-nf-eletro = nota-fiscal.idi-sit-nf-eletro
tt-relatorio.imp-nota = natur-oper.imp-nota.
soma-vl-cont-doc = 0.
soma-vl-bicms = 0.
soma-vl-icms = 0.
soma-vl-icmsou = 0.
soma-vl-ipiou = 0.
soma-vl-ipi = 0.
END.
GET NEXT qRelatorio.
END.
With this, I managed to get the answers I wanted andthe query is quite fast. If there's any suggestions as to how make it faster, I'm open for them. Thanks.
Related
How to take a result on another page in asp.net?
Image1.Visible = true; Label2.Text = "Correct Ans = " + answer.ToString(); Label3.Text = "Incorrect Ans = " + wrong.ToString(); Label20.Text = "Total Questions = " + count.ToString(); Label21.Text = "Score = " + answer* 10; Label26.Text = "Percentage = " + Math.Round(answer / count* 100)+ " %"; answer = 0; wrong = 0;
There are many different ways to achieve this.I would suggest you read A Beginner's Tutorial on ASP.NET State Management and decide which one suits you best Here's a simple example which uses three of these technologies, namely: Query strings Session state Cookies Setting values: string name = txtName.Text; //1.Session Session["name"] = name; //2.Cookies Response.Cookies["name"].Value = name; Response.Cookies["name"].Expires = DateTime.Now.AddDays(1); //3.Query strings Response.Redirect("Page2.aspx?name=" + name); Reading values: //1.Session string nameFromSession = Session["name"] as string; //2.Cookies string nameFromCookie = Request.Cookies["name"].Value; //3.Query strings string nameFromQueryString = Request.QueryString["name"];
Putting labels inside of a vb.net Array
So i've created 5 different arrays for labels These are Dim ovsoLabels As Label(), customerLabels() As Label, itemNameLabels() As Label, quantityLabels() As Label, topRightItemNameLbls(5) As Label Dim indexLabels() As Label After that I have a function that assigns those variables to actual labels. 'assign labels to array ovsoLabels(0) = oVSO10 ovsoLabels(1) = oVSO11 ovsoLabels(2) = oVSO12 ovsoLabels(3) = oVSO13 ovsoLabels(4) = oVSO14 customerLabels(0) = custLbl20 customerLabels(1) = custLbl21 customerLabels(2) = custLbl22 customerLabels(3) = custLbl23 customerLabels(4) = custLbl24 itemNameLabels(0) = nameLbl1 itemNameLabels(1) = nameLbl2 itemNameLabels(2) = nameLbl3 itemNameLabels(3) = nameLbl4 itemNameLabels(4) = nameLbl5 quantityLabels(0) = quantLbl1 quantityLabels(1) = quantLbl2 quantityLabels(2) = quantLbl3 quantityLabels(3) = quantLbl4 quantityLabels(4) = quantLbl6 indexLabels(0) = indexLbl10 indexLabels(1) = indexLbl11 indexLabels(2) = indexLbl12 indexLabels(3) = indexLbl13 indexLabels(4) = indexLbl14 After that I call the function in my timer tick and this is what i'm triying to do (Not quoteArray has numbers in it 0 - infinity) For i = 0 To 4 If quantityArray(i) = Nothing Then ElseIf quantityArray(i) = 0 Then quantityLabels(i).ForeColor = Drawing.Color.Green customerLabels(i).ForeColor = Drawing.Color.Green itemNameLabels(i).ForeColor = Drawing.Color.Green ovsoLabels(i).ForeColor = Drawing.Color.Green indexLabels(i).ForeColor = Drawing.Color.Green Else quantityLabels(i).ForeColor = Drawing.Color.Black customerLabels(i).ForeColor = Drawing.Color.Black itemNameLabels(i).ForeColor = Drawing.Color.Black ovsoLabels(i).ForeColor = Drawing.Color.Black indexLabels(i).ForeColor = Drawing.Color.Black End If Next This is my first post, so tell me if I can format better. The error I'm getting is that it tells me that there is no object and I need to use the keyword new. Not sure what that means, thanks!
Tkinter Module refresh window
My program is for a hangman game and I can't get the window to refresh once the button is clicked. At least i think that is the problem Here is my code for the window and the function linked to the button, let me know if you need more code: def game(self, num): self.game_window = tkinter.Tk() self.game_window.title('Hangman') self.game_window.geometry('200x150') self.f1 = tkinter.Frame(self.game_window) self.f2 = tkinter.Frame(self.game_window) self.f3 = tkinter.Frame(self.game_window) self.f4 = tkinter.Frame(self.game_window) self.f5 = tkinter.Frame(self.game_window) self.f6 = tkinter.Frame(self.game_window) self.f7 = tkinter.Frame(self.game_window) self.f8 = tkinter.Frame(self.game_window) self.f9 = tkinter.Frame(self.game_window) self.num = num word_list = ['PYTHON','SOMETHING','COMPLETELY','DIFFERENT', 'LIST','STRING','SYNTAX','OBJECT','ERROR', 'EXCEPTION','OBJECT','CLASS','PERFORMANCE','VISUAL', 'JAVASCRIPT','JAVA','PROGRAMMING','TUPLE','ASSIGN', 'FUNCTION','OPERATOR','OPERANDS','PRECEDENCE', 'LOOPS','SENTENCE','TABLE','NUMBERS','DICTIONARY', 'GAME','SOFTWARE','NETWORK','SOCIAL','EDUCATION', 'MONITOR','COMPUTER'] shuffle = random.shuffle(word_list) rand = random.choice(word_list) self.word = rand.lower() self.current = len(self.word)*'*' self.letters = [] #self.start_lives = tkinter.Label(self.f1, text = 'You\'ve started the ' #'game with %s lives.\n'%(self.num)) #self.start_lives.pack(side = 'left') self.lives_rem = tkinter.Label(self.f2, text = 'Lives remaining: '+str(self.lives_left())) self.lives_rem.pack(side = 'left') self.guess_letter = tkinter.Label(self.f3, text = 'Guess a letter: ') self.guess_entry = tkinter.Entry(self.f3, width = 10) self.guess_letter.pack(side = 'left') self.guess_entry.pack(side = 'left') #self.f1.pack() self.f2.pack() self.f3.pack() self.guess_button = tkinter.Button(self.f6, text = 'Guess!', command = self.update(self.guess_entry.get())) self.guess_button.pack(side = 'left') self.quit_game = tkinter.Button(self.f6, text = 'Quit Game', command = self.game_window.destroy) self.quit_game.pack(side = 'left') self.f6.pack() def update(self, letter): if letter in self.word and letter not in self.letters: pos = self.word.index(letter) self.current1 = list(self.current) self.current1[pos] = letter.upper() self.current2 = ''.join(self.current1) self.letters.append(letter) elif letter in self.letters: self.already_guessed = tkinter.messagebox.showinfo('Error!', 'This letter has already ' 'been guessed') #letter is not in the word elif letter not in self.word: self.sorry = tkinter.Label(self.f5, text = 'Sorry, guess again!') self.sorry.pack(side = 'left') self.letters.append(letter) self.num -= 1 self.incorrect_word = tkinter.Label(self.f4, text = 'Word: '+self.current) self.incorrect_word.pack(side='left') self.f5.pack() self.f4.pack() return self.current These are two methods in a Hangman class.
The line that defines the guess button: self.guess_button = tkinter.Button(self.f6, text = 'Guess!', command = self.update(self.guess_entry.get())) requires modification. the command argument for the Button class should be a function, but this line is calling that function (which sends the output of the function as the value for the command argument). As you may see on the quit_game button definition, the self.game_window.destroy function is provided as the command, but is not called right now. I suggest changing this line like this: self.guess_button = tkinter.Button(self.f6, text = 'Guess!', command = self._on_guess_button_click) and then add a new method to your class like this: def _on_guess_button_click (self): self.update(self.guess_entry.get())
Routed Direction using GooglemapforAsp.net control
I'm trying to research the routed direction using google maps for asp.net control. Here is my Code. GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"]; GoogleMapForASPNet1.GoogleMapObject.Width = "1100px"; GoogleMapForASPNet1.GoogleMapObject.Height = "600px"; GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 10; GoogleMapForASPNet1.GoogleMapObject.CenterPoint = new GooglePoint("1", 1.352083, 103.819836); GoogleMapForASPNet1.GoogleMapObject.ShowTraffic = true; int count=0; bool flag = false; GoogleMapForASPNet1.GoogleMapObject.Points.Clear(); foreach (var gitem in tblG) { foreach (var item in tblDT) { if (item.Latitude==gitem.Latitude && item.Longitude==gitem.Longitude && flag!=true) { count += 1; GooglePoint GP1 = new GooglePoint(); GP1.ID = "GP" + count.ToString(); GP1.Latitude = Convert.ToDouble(gitem.Latitude);//latitude; GP1.Longitude = Convert.ToDouble(gitem.Longitude); GP1.InfoHTML = " Name:<b>" + Name + "</b></br>Point:<b>" + "GP" + count.ToString() + "</b></br>Time:<b>" + gitem.CDate.ToString() + "</b></br>";//stime; GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP1); string address = gitem.Latitude + "," + gitem.Longitude; GoogleMapForASPNet1.GoogleMapObject.Directions.Addresses.Add(address); flag = true; } } flag = false; } I want it as Routed Direction is only between start and End point. But I got result look like driving Direction. I don't want to get that result. How to fix that problem?
'String' does not contain a reference for 'Text'
The .Text on add is giving the error, I believe I have the right assemblies in place. StringCollection sc = new StringCollection(); for (int i = 1; i <= 2; i++) { //extract the TextBox values string txt1 = ((TextBox)Page.FindControl("TextBox1" + i.ToString())).Text; string txt2 = ((TextBox)Page.FindControl("TextBox2" + i.ToString())).Text; string txt3 = ((TextBox)Page.FindControl("TextBox3" + i.ToString())).Text; string txt4 = ((TextBox)Page.FindControl("TextBox4" + i.ToString())).Text; string txt5 = ((TextBox)Page.FindControl("TextBox5" + i.ToString())).Text; string txt6 = ((TextBox)Page.FindControl("TextBox6" + i.ToString())).Text; string txt7 = ((TextBox)Page.FindControl("TextBox7" + i.ToString())).Text; string txt8 = ((TextBox)Page.FindControl("TextBox8" + i.ToString())).Text; string txt9 = ((TextBox)Page.FindControl("TextBox9" + i.ToString())).Text; sc.Add(txt1.Text, txt2.Text, txt3.Text, txt4.Text, txt5.Text, txt6.Text, txt7.Text, txt8.Text, txt9.Text); } InsertRecords(sc);
You are basically calling string.Text since the type of txt1, txt2, etc is string, hence the error. But note that you are already calling .Text on the TextField control so what you probably intend to do is: sc.AddRange(new string[]{txt1, txt2, txt3, ...});