Example #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            String  vrijemeRada = WorkTimeTB.Text;
            decimal rabat       = decimal.Parse(RebateTB.Text);
            int     kolicina    = int.Parse(QuantityTB.Text);

            radioButtonENG.Enabled = false;
            radioButtonHRV.Enabled = false;

            try
            {
                OfferParts offerPart = new OfferParts(ponudaID, tempSifPart.FullCode, vrijemeRada, rabat, kolicina);

                int indx = offerPart.Compare(offerPartsList, offerPart);
                if (indx >= 0)
                {
                    listView1.Items[indx].SubItems[6].Text = (offerPartsList.ElementAt(indx).Kolicina += offerPart.Kolicina).ToString();
                    offerPartsList[indx].IznosTotal        = String.Format("{0:N2}", decimal.Parse(offerPartsList[indx].IznosTotal) + offerPart.Kolicina * decimal.Parse(offerPartsList[indx].IznosRabat));
                    listView1.Items[indx].SubItems[8].Text = offerPartsList.ElementAt(indx).IznosTotal;
                    addToList(false, true, offerPart);

                    SystemSounds.Hand.Play();
                }
                else
                {
                    offerPartsList.Add(offerPart);

                    addToList(false, false, offerPart);

                    recalculateInvPart = offerPart;
                }

                PartNameCB.Focus();
            }
            catch (Exception e1)
            {
                new LogWriter(e1);
                MessageBox.Show(e1.Message);
            }
        }
Example #2
0
        private void addToList(Boolean remove, Boolean update, OfferParts invPrt)
        {
            ///////////////// LogMe ////////////////////////
            String    function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name;
            String    usedQC   = "Add to list";
            String    data     = "";
            String    Result   = "";
            LogWriter lw       = new LogWriter();
            ////////////////////////////////////////////////
            ///

            decimal cijena = 0;
            decimal popust = 0;


            decimal partTotal  = 0;
            decimal partsTotal = 0;

            //decimal cijena = decimal.Parse(CheckIfKNZero(tempSifPart));
            if (!remove)
            {
                decimal kn  = tempSifPart.PriceOutKn;
                decimal eur = tempSifPart.PriceOutEur;

                if (radioButtonENG.Checked)
                {
                    cijena = eur > 0 ?  eur : kn / (decimal)ech;
                }
                else
                {
                    cijena = kn > 0 ? kn : eur * (decimal)ech;
                }

                popust = invPrt.Rabat;


                partTotal  = invPrt.PartTotalPrice(cijena, popust, invPrt.VrijemeRada);
                partsTotal = partTotal * invPrt.Kolicina;

                //TOTAL += partsTotal;
                TOTALTAXBASE += partsTotal;
                TOTALTAX      = TOTALTAXBASE * vat;
                TOTAL         = TOTALTAX + TOTALTAXBASE;

                offer.Iznos = TOTAL;
            }
            else
            {
                cijena = decimal.Parse(invPrt.IznosTotal);

                //TOTAL += partsTotal;
                TOTALTAXBASE -= cijena;
                TOTALTAX      = TOTALTAXBASE * vat;
                TOTAL         = TOTALTAX + TOTALTAXBASE;

                offer.Iznos = TOTAL;
            }

            try
            {
                String dd;

                if (!remove && !update)
                {
                    ListViewItem lvi1 = new ListViewItem();
                    rb        = listView1.Items.Count + 1;
                    lvi1.Text = rb.ToString();

                    lvi1.SubItems.Add(tempSifPart.FullName);
                    lvi1.SubItems.Add(mainCmp.Code.ToString() + customerCmp.Code.ToString() + Decoder.GetFullPartCodeStr(tempSifPart.FullCode));
                    lvi1.SubItems.Add(String.Format("{0:0.00}", cijena));
                    lvi1.SubItems.Add(invPrt.VrijemeRada);
                    lvi1.SubItems.Add(String.Format("{0:0.00}", invPrt.Rabat));
                    lvi1.SubItems.Add(String.Format("{0:#0}", invPrt.Kolicina));
                    lvi1.SubItems.Add(String.Format("{0:0.00}", partTotal));
                    lvi1.SubItems.Add(String.Format("{0:0.00}", partsTotal));

                    if (listView1.Items.Count > 1)
                    {
                        listView1.EnsureVisible(listView1.Items.Count - 1);
                    }

                    listView1.Items.Add(lvi1);

                    dd = tempSifPart.FullName + ", " + Decoder.GetFullPartCodeStr(tempSifPart.FullCode.ToString()) + ", " + tempSifPart.PriceInKn.ToString() + ", " + invPrt.VrijemeRada + ", " + invPrt.Rabat.ToString() + ", " + invPrt.Kolicina.ToString() + ", " + partTotal + ", " + partsTotal + ", " + TOTAL.ToString();
                    invPrt.IznosPart  = String.Format("{0:N2}", cijena);
                    invPrt.IznosRabat = String.Format("{0:N2}", partTotal);
                    invPrt.IznosTotal = String.Format("{0:N2}", partsTotal);

                    if (data.Equals(""))
                    {
                        data = dd;
                    }
                    else
                    {
                        data = data + Environment.NewLine + "             " + dd;
                    }
                }
                else
                {
                    dd = tempSifPart.FullName + ", " + Decoder.GetFullPartCodeStr(tempSifPart.FullCode.ToString()) + ", " + tempSifPart.PriceInKn.ToString() + ", " + invPrt.VrijemeRada + ", " + invPrt.Rabat.ToString() + ", " + invPrt.Kolicina.ToString() + ", " + partTotal + ", " + partsTotal + ", " + TOTAL.ToString();
                    if (data.Equals(""))
                    {
                        data = dd;
                    }
                    else
                    {
                        data = data + Environment.NewLine + "             " + dd;
                    }
                }

                if (radioButtonENG.Checked)
                {
                    TaxBaseLB.Text = String.Format("{0:0.00}", TOTALTAXBASE * (decimal)ech);
                    VATLB.Text     = String.Format("{0:0.00}", TOTALTAX * (decimal)ech);

                    TotalEURLB.Text = String.Format("{0:0.00}", TOTAL);
                    TotalKNLB.Text  = String.Format("{0:0.00}", (TOTAL * (decimal)ech));
                }
                else
                {
                    TaxBaseLB.Text = String.Format("{0:0.00}", TOTALTAXBASE);
                    VATLB.Text     = String.Format("{0:0.00}", TOTALTAX);

                    TotalEURLB.Text = String.Format("{0:0.00}", TOTAL / (decimal)ech);
                    TotalKNLB.Text  = String.Format("{0:0.00}", TOTAL);
                }
            }
            catch (Exception e1)
            {
                new LogWriter(e1);
                MessageBox.Show(e1.Message);
            }

            for (int i = 0; i < listView1.Columns.Count; i++)
            {
                listView1.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent);
                listView1.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.HeaderSize);
            }

            //if (clear)
            //{
            //    textBox1.Clear();
            //    textBox2.Clear();
            //    textBox3.Clear();
            //}

            //textBox1.SelectAll();
            //isFocused = true;
            //textBox1.Focus();
            //isFocused = false;

            Result = "Added";
            lw.LogMe(function, usedQC, data, Result);

            SystemSounds.Hand.Play();
        }