예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ///////////////// LogMe ////////////////////////
            String    function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name;
            String    usedQC   = "Save to db";
            String    data     = "";
            String    Result   = "";
            LogWriter lw       = new LogWriter();

            ////////////////////////////////////////////////
            ///

            IUSNumber = "";

            if (this.label2.Text.Equals("Name"))
            {
                Result = "Please select company, nothing done.";
                lw.LogMe(function, usedQC, data, Result);
                MessageBox.Show(Result);
                textBox1.SelectAll();
                isFocused = true;
                textBox1.Focus();
                isFocused = false;
            }
            else if (this.listView1.Items.Count == 0)
            {
                Result = "There is no items in list, nothing done.";
                lw.LogMe(function, usedQC, data, Result);
                MessageBox.Show(Result);
                textBox1.SelectAll();
                isFocused = true;
                textBox1.Focus();
                isFocused = false;
            }
            else
            {
                //List<Part> listOfOtpPartsPrimka = new List<Part>();
                MainCmp mpc = new MainCmp();
                mpc.GetMainCmpByName(Properties.Settings.Default.CmpName);
                cmpR.Clear();
                cmpR = mpc.MainCmpToCompany();

                if (cmpS.GetCompanyByName(label2.Text.Trim()))
                {
                    try
                    {
                        List <String>    arr = new List <string>();
                        ConnectionHelper cn  = new ConnectionHelper();
                        using (SqlConnection cnnIUS = cn.Connect(WorkingUser.Username, WorkingUser.Password))
                        {
                            if (cn.TestConnection(cnnIUS))
                            {
                                //Provjera da li se dijelovi nalaze u mom skladistu
                                QueryCommands qc = new QueryCommands();

                                for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu)
                                {
                                    if (qc.GetPartIDCompareCodeSNCNStorageState(WorkingUser.Username, WorkingUser.Password,
                                                                                long.Parse(listView1.Items[i].SubItems[2].Text),
                                                                                listView1.Items[i].SubItems[3].Text,
                                                                                listView1.Items[i].SubItems[4].Text,
                                                                                WorkingUser.RegionID, "ng")[0].Equals("nok"))
                                    {
                                        data   = listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1);
                                        Result = "In your storage does not exist NG part with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + "\n\nNothing Done.";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result);
                                        textBox1.SelectAll();
                                        isFocused = true;
                                        textBox1.Focus();
                                        isFocused = false;
                                        return;
                                    }
                                }

                                //Provjera i spremanje u bazu
                                List <String> allRegions = new List <string>();
                                allRegions = qc.GetAllRegions();

                                int index = resultArrC.FindIndex(resultArrC => resultArrC.Name.Equals(label2.Text));

                                List <Part> partList    = new List <Part>();
                                String      napomenaIUS = textBox4.Text;

                                for (int i = 0; i < listView1.Items.Count; i++)
                                {
                                    PartSifrarnik tempSifPart = new PartSifrarnik();
                                    Part          tempPart    = new Part();

                                    foreach (Part part in partsArr)
                                    {
                                        tempSifPart.GetPart(Decoder.GetFullPartCodeStr(listView1.Items[i].SubItems[2].Text));

                                        if (part.PartialCode == tempSifPart.FullCode && part.SN.ToUpper().Equals(listView1.Items[i].SubItems[3].Text.ToUpper()) && part.CN.ToUpper().Equals(listView1.Items[i].SubItems[4].Text.ToUpper()) && !partList.Contains(part))
                                        {
                                            tempPart           = part;
                                            tempPart.StorageID = WorkingUser.RegionID;
                                            tempPart.State     = "sng";
                                            tempPart.CompanyO  = Decoder.GetOwnerCode(listView1.Items[i].SubItems[2].Text);
                                            tempPart.CompanyC  = Decoder.GetCustomerCode(listView1.Items[i].SubItems[2].Text);
                                            break;
                                        }
                                    }

                                    String tmpResult = qc.GetListPartsByPartIDFromParts(tempPart.PartID)[0];

                                    if (tmpResult.Equals("nok"))
                                    {
                                        data   = listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1);
                                        Result = "There is no NG part in your storage with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + ". \n\nNothing Done.";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result);
                                        textBox1.SelectAll();
                                        isFocused = true;
                                        textBox1.Focus();
                                        isFocused = false;
                                        return;
                                    }
                                    else
                                    {
                                        tempPart.PartID = long.Parse(tmpResult);
                                        partList.Add(tempPart);
                                    }
                                }

                                IUSNumber = qc.IUSPrebaciUServis(WorkingUser.Username, WorkingUser.Password, partList, WorkingUser.RegionID, cmpS.ID, napomenaIUS);
                                if (!IUSNumber.Equals("nok"))
                                {
                                    partsArr = partsArr.Except(partList).ToList();

                                    PovijestLog pl = new PovijestLog();

                                    if (Program.SaveDocumentsPDF)
                                    {
                                        saveToPDF(partList);
                                    }

                                    if (pl.SaveToPovijestLog(partList, DateTime.Now.ToString("dd.MM.yy."), napomenaIUS, cmpS.Name, "", "", "IUS " + Properties.Settings.Default.ShareDocumentName, "sng"))
                                    {
                                        Properties.Settings.Default.ShareDocumentName = "";

                                        Result = "DONE, document nbr. IUS '" + IUSNumber + "'.";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result);

                                        partListPrint.Clear();
                                        partListPrint.AddRange(partList);

                                        isIUSSaved = true;
                                        listView1.Clear();
                                        listView1.View = View.Details;

                                        listView1.Columns.Add("RB");
                                        listView1.Columns.Add("Name");
                                        listView1.Columns.Add("Code");
                                        listView1.Columns.Add("SN");
                                        listView1.Columns.Add("CN");
                                        listView1.Columns.Add("Condition");
                                        textBox4.Clear();
                                        napomenaIUSPrint = napomenaIUS;
                                    }
                                    else
                                    {
                                        Result = "DONE, document nbr. 'IUS " + IUSNumber + "', but not saved in PL.";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result);

                                        partListPrint.Clear();
                                        partListPrint.AddRange(partList);

                                        isIUSSaved = true;
                                        listView1.Clear();
                                        listView1.View = View.Details;

                                        listView1.Columns.Add("RB");
                                        listView1.Columns.Add("Name");
                                        listView1.Columns.Add("Code");
                                        listView1.Columns.Add("SN");
                                        listView1.Columns.Add("CN");
                                        listView1.Columns.Add("Condition");
                                        textBox4.Clear();
                                        napomenaIUSPrint = napomenaIUS;
                                    }
                                }
                                else
                                {
                                    Result = "Unknown error in QUERY.";
                                    lw.LogMe(function, usedQC, data, Result);
                                    MessageBox.Show(Result);
                                    napomenaIUSPrint = "";
                                    isIUSSaved       = false;
                                }
                                //}
                            }
                            cnnIUS.Close();
                        }
                    }
                    catch (Exception e1)
                    {
                        new LogWriter(e1);
                        MessageBox.Show(e1.Message);
                        textBox1.SelectAll();
                        isFocused = true;
                        textBox1.Focus();
                        isFocused = false;
                    }
                }
                this.printPrewBT.Enabled = isIUSSaved;
            }
        }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            ///////////////// LogMe ////////////////////////
            String    function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name;
            String    usedQC   = "Save to db";
            String    data     = "";
            String    Result   = "";
            LogWriter lw       = new LogWriter();
            ////////////////////////////////////////////////
            ///

            Dictionary <String, int> groupArr = new Dictionary <string, int>();

            int ind;

            ind = comboBox5.FindStringExact(comboBox5.Text);

            if (ind < 0)
            {
                comboBox5.ResetText();
            }

            OTPNumber = "";

            if (this.label2.Text.Equals("Name"))
            {
                Result = "Please select company, nothing done.";
                lw.LogMe(function, usedQC, data, Result);
                MessageBox.Show(Result);
                textBox1.SelectAll();
                textBox1.Focus();
            }
            else if (this.listView1.Items.Count == 0)
            {
                Result = "There is no items in list, nothing done.";
                lw.LogMe(function, usedQC, data, Result);
                MessageBox.Show(Result);
                textBox1.SelectAll();
                textBox1.Focus();
            }
            else
            {
                MainCmp mpc = new MainCmp();
                mpc.GetMainCmpByName(Properties.Settings.Default.CmpName);
                cmpS.Clear();
                cmpS = mpc.MainCmpToCompany();

                if (cmpR.GetCompanyByName(label2.Text.Trim()))
                {
                    try
                    {
                        List <String>    arr = new List <string>();
                        ConnectionHelper cn  = new ConnectionHelper();
                        using (SqlConnection cnnPR = cn.Connect(WorkingUser.Username, WorkingUser.Password))
                        {
                            QueryCommands qc = new QueryCommands();

                            if (cn.TestConnection(cnnPR))
                            {
                                //Provjera da li brojcano odgovaraju dijelovi

                                String testStr;

                                groupArr.Add(listView1.Items[0].SubItems[2].Text + "_" + listView1.Items[0].SubItems[3].Text + "_" +
                                             listView1.Items[0].SubItems[4].Text + "_" + listView1.Items[0].SubItems[5].Text + "_" + WorkingUser.RegionID.ToString(), 1);

                                for (int i = 1; i < listView1.Items.Count; i++)
                                {
                                    testStr = listView1.Items[i].SubItems[2].Text + "_" + listView1.Items[i].SubItems[3].Text + "_" +
                                              listView1.Items[i].SubItems[4].Text + "_" + listView1.Items[i].SubItems[5].Text + "_" + WorkingUser.RegionID.ToString();

                                    if (groupArr.ContainsKey(testStr))
                                    {
                                        groupArr[testStr] = groupArr[testStr] + 1;
                                    }
                                    else
                                    {
                                        groupArr.Add(testStr, 1);
                                    }
                                }

                                for (int i = 0; i < groupArr.Count(); i++)
                                {
                                    var testArr = groupArr.ElementAt(i).Key.Split('_');

                                    int prtConut = qc.GetPartCountByCodeSNCNStateStorage(WorkingUser.Username, WorkingUser.Password,
                                                                                         long.Parse(testArr[0]),
                                                                                         testArr[1],
                                                                                         testArr[2],
                                                                                         testArr[3],
                                                                                         long.Parse(testArr[4]));

                                    if (groupArr[groupArr.ElementAt(i).Key] > prtConut)
                                    {
                                        data   = testArr[0] + ", " + testArr[1] + ", " + testArr[2] + ", " + testArr[3] + ", " + prtConut + ", " + groupArr[groupArr.ElementAt(i).Key];
                                        Result = "You do not have enough patrs in you storage:" +
                                                 "\n\n Code: " + testArr[0] +
                                                 "\n SN:  " + testArr[1] +
                                                 "\n CN:  " + testArr[2] +
                                                 "\n State: " + testArr[3] +
                                                 "\n\nYou have: " + prtConut +
                                                 "\nYou want: " + groupArr[groupArr.ElementAt(i).Key] +
                                                 "\n\nNothing Done.";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result, "Caution", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        return;
                                    }
                                }

                                //Provjera da li se dijelovi nalaze u mom skladistu
                                for (int i = 0; i < listView1.Items.Count; i++)
                                {
                                    if (qc.GetPartIDCompareCodeSNCNStorage(WorkingUser.Username, WorkingUser.Password,
                                                                           long.Parse(listView1.Items[i].SubItems[2].Text),
                                                                           listView1.Items[i].SubItems[3].Text,
                                                                           listView1.Items[i].SubItems[4].Text,
                                                                           WorkingUser.RegionID)[0].Equals("nok"))
                                    {
                                        data   = listView1.Items[i].SubItems[2].Text + ", " + listView1.Items[i].Index + 1;
                                        Result = "There is no part in your storage with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + ". \n\nNothing Done.";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result);

                                        textBox1.SelectAll();
                                        textBox1.Focus();
                                        return;
                                    }
                                }

                                //Provjera i spremanje u bazu
                                List <String> allRegions = new List <string>();
                                allRegions = qc.GetAllRegions();

                                int index = resultArrC.FindIndex(resultArrC => resultArrC.Name.Equals(label2.Text));

                                if (resultArrC[index].RegionID != WorkingUser.RegionID)
                                {
                                    for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu)
                                    {
                                        //long test = long.Parse(listView1.Items[i].SubItems[2].Text.Substring(4)); //DecoderBB
                                        long test = Decoder.GetFullPartCodeLng(listView1.Items[i].SubItems[2].Text);
                                        if (!resultArrSearchCode.Contains(test.ToString()))
                                        {
                                            data   = test.ToString() + ", " + listView1.Items[i].Index + 1;
                                            Result = "There is no part in 'Sifrarnik' with code, = " + test.ToString() + "\n" + "on position " + (listView1.Items[i].Index + 1) + "  \n\nNothing Done.";
                                            lw.LogMe(function, usedQC, data, Result);
                                            MessageBox.Show(Result);

                                            textBox1.SelectAll();
                                            textBox1.Focus();
                                            return;
                                        }
                                    }

                                    //Provjera da li se dijelovi nalaze u mom skladistu i dohvacanje dijelova
                                    List <Part> partList    = new List <Part>();
                                    String      napomenaOTP = napomenaOTPPrint = textBox4.Text;

                                    for (int i = 0; i < groupArr.Count(); i++)
                                    {
                                        PartSifrarnik tempSifPart = new PartSifrarnik();
                                        List <Part>   tempParts   = new List <Part>();
                                        Part          tempPart    = new Part();

                                        tempSifPart.GetPart(Decoder.GetFullPartCodeStr(listView1.Items[i].SubItems[2].Text));

                                        tempParts = tempPart.GetListOfParts(long.Parse(groupArr.ElementAt(i).Key.Split('_')[0]), groupArr.ElementAt(i).Key.Split('_')[1],
                                                                            groupArr.ElementAt(i).Key.Split('_')[2], groupArr.ElementAt(i).Key.Split('_')[3], long.Parse(groupArr.ElementAt(i).Key.Split('_')[4]));

                                        if (tempParts.Count() < groupArr[groupArr.ElementAt(i).Key])
                                        {
                                            data   = groupArr.ElementAt(i).Key.Split('_')[0] + ", " + groupArr.ElementAt(i).Key.Split('_')[1] + ", " + groupArr.ElementAt(i).Key.Split('_')[2] + ", " + groupArr.ElementAt(i).Key.Split('_')[3] + ", " + tempParts.Count + ", " + groupArr[groupArr.ElementAt(i).Key];
                                            Result = "There is no part in your storage with:" + "" +
                                                     "\n\n Code: " + groupArr.ElementAt(i).Key.Split('_')[0] +
                                                     "\n SN:  " + groupArr.ElementAt(i).Key.Split('_')[1] +
                                                     "\n CN:  " + groupArr.ElementAt(i).Key.Split('_')[2] +
                                                     "\n State: " + groupArr.ElementAt(i).Key.Split('_')[3] +
                                                     "\n\nYou have: " + tempParts.Count +
                                                     "\nYou want: " + groupArr[groupArr.ElementAt(i).Key] +
                                                     "\n\nNothing Done.";
                                            lw.LogMe(function, usedQC, data, Result);
                                            MessageBox.Show(Result, "Caution", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                                            textBox1.SelectAll();
                                            textBox1.Focus();
                                            return;
                                        }
                                        else
                                        {
                                            int kk = 0;
                                            foreach (Part prt in tempParts)
                                            {
                                                partList.Add(prt);
                                                kk++;
                                                if (kk == groupArr[groupArr.ElementAt(i).Key])
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    //SPREMANJE U BAZU
                                    if (resultArrC[index].RegionID != Properties.Settings.Default.OstaliIDRegion &&
                                        resultArrC[index].RegionID != Properties.Settings.Default.TransportIDRegion &&
                                        resultArrC[index].RegionID != Properties.Settings.Default.ServisIDRegion)
                                    {
                                        OTPNumber = qc.OTPUnesiUredajeDaSuPrimljeniInner(WorkingUser.Username, WorkingUser.Password, partList, cmpR, cmpS, textBox4.Text, 0);
                                    }
                                    else if (resultArrC[index].RegionID != Properties.Settings.Default.TransportIDRegion &&
                                             resultArrC[index].RegionID != Properties.Settings.Default.ServisIDRegion)
                                    {
                                        OTPNumber = qc.OTPUnesiUredajeDaSuPrimljeni(WorkingUser.Username, WorkingUser.Password, partList, cmpR, cmpS, textBox4.Text, br.FilID);
                                    }
                                    else
                                    {
                                        Result = "Hm... You cant send part to service!";
                                        lw.LogMe(function, usedQC, data, Result);
                                        MessageBox.Show(Result);

                                        textBox1.SelectAll();
                                        textBox1.Focus();
                                        return;
                                    }

                                    if (!OTPNumber.Equals("nok"))
                                    {
                                        PovijestLog pl    = new PovijestLog();
                                        Boolean     saved = false;
                                        for (int k = 0; k < partList.Count; k++)
                                        {
                                            List <Part> tempPart = new List <Part>();
                                            tempPart.Clear();
                                            tempPart.Add(new Part());
                                            tempPart.Add(partList[k]);
                                            if (pl.SaveToPovijestLog(tempPart, DateTime.Now.ToString("dd.MM.yy."), napomenaOTP, cmpR.Name, "", "", "OTP " + Properties.Settings.Default.ShareDocumentName, tempPart[1].State))
                                            {
                                                saved = true;
                                            }
                                            else
                                            {
                                                saved = false;
                                                Properties.Settings.Default.ShareDocumentName = "";
                                                break;
                                            }
                                        }

                                        if (Program.SaveDocumentsPDF)
                                        {
                                            saveToPDF(partList);
                                        }

                                        if (saved)
                                        {
                                            Result = "DONE, document nbr. OTP '" + OTPNumber + "'.";
                                            lw.LogMe(function, usedQC, data, Result);
                                            MessageBox.Show(Result);

                                            partListPrint.Clear();
                                            partListPrint.AddRange(partList);

                                            isOtpremnicaSaved = true;
                                            listView1.Clear();
                                            listView1.View = View.Details;

                                            listView1.Columns.Add("RB");
                                            listView1.Columns.Add("Name");
                                            listView1.Columns.Add("Code");
                                            listView1.Columns.Add("SN");
                                            listView1.Columns.Add("CN");
                                            listView1.Columns.Add("Condition");
                                            textBox4.Clear();
                                            napomenaOTPPrint = napomenaOTP;
                                        }
                                        else
                                        {
                                            Result = "DONE, document nbr. 'OTP " + OTPNumber + "', but not saved in PL.";
                                            lw.LogMe(function, usedQC, data, Result);
                                            MessageBox.Show(Result);

                                            partListPrint.Clear();
                                            partListPrint.AddRange(partList);

                                            isOtpremnicaSaved = true;
                                            listView1.Clear();
                                            listView1.View = View.Details;

                                            listView1.Columns.Add("RB");
                                            listView1.Columns.Add("Name");
                                            listView1.Columns.Add("Code");
                                            listView1.Columns.Add("SN");
                                            listView1.Columns.Add("CN");
                                            listView1.Columns.Add("Condition");
                                            textBox4.Clear();
                                            napomenaOTPPrint = napomenaOTP;
                                        }
                                    }
                                }
                                else
                                {
                                    Result = "Hm... Same receiving and sending company?!";
                                    lw.LogMe(function, usedQC, data, Result);
                                    MessageBox.Show(Result);

                                    textBox1.SelectAll();
                                    textBox1.Focus();
                                    return;
                                }
                            }
                            cnnPR.Close();
                        }
                    }
                    catch (Exception e1)
                    {
                        new LogWriter(e1);
                        MessageBox.Show(e1.Message);
                        textBox1.SelectAll();
                        textBox1.Focus();
                    }
                }
                this.printPrewBT.Enabled = isOtpremnicaSaved;
            }
        }
예제 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            Program.SaveStart();

            ///////////////// LogMe ////////////////////////
            String    function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name;
            String    usedQC   = "Save to db";
            String    data     = "";
            String    Result   = "";
            LogWriter lw       = new LogWriter();

            ////////////////////////////////////////////////
            ///

            PrimkaNumber = "";

            if (this.label2.Text.Equals("Name"))
            {
                Result = "Please select company, nothing done.";
                lw.LogMe(function, usedQC, data, Result);

                Program.SaveStop();
                MessageBox.Show(Result);

                textBox1.SelectAll();
                textBox1.Focus();
            }
            else if (this.listView1.Items.Count == 0)
            {
                Result = "There is no items in list, nothing done.";
                lw.LogMe(function, usedQC, data, Result);

                Program.SaveStop();
                MessageBox.Show(Result);

                textBox1.SelectAll();
                textBox1.Focus();
            }
            else
            {
                List <Part> listOfOtpPartsFromOTP = new List <Part>();
                //List<Part> listOfOtpPartsPrimka = new List<Part>();
                MainCmp mpc = new MainCmp();
                mpc.GetMainCmpByName(Properties.Settings.Default.CmpName);
                cmpR.Clear();
                cmpR = mpc.MainCmpToCompany();

                if (cmpS.GetCompanyByName(label2.Text.Trim()))
                {
                    try
                    {
                        List <String>    arr = new List <string>();
                        SqlCommand       commandPR;
                        String           queryPR;
                        ConnectionHelper cn = new ConnectionHelper();
                        using (SqlConnection cnnPR = cn.Connect(WorkingUser.Username, WorkingUser.Password))
                        {
                            if (cn.TestConnection(cnnPR))
                            {
                                //Provjera da li se dijelovi nalaze u mom skladistu
                                QueryCommands qc = new QueryCommands();

                                for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu)
                                {
                                    if (!listView1.Items[i].SubItems[3].Text.Equals("") && !listView1.Items[i].SubItems[4].Text.Equals(""))
                                    {
                                        if (!qc.GetPartIDCompareCodeSNCNStorage(WorkingUser.Username, WorkingUser.Password,
                                                                                long.Parse(listView1.Items[i].SubItems[2].Text),
                                                                                listView1.Items[i].SubItems[3].Text,
                                                                                listView1.Items[i].SubItems[4].Text,
                                                                                WorkingUser.RegionID)[0].Equals("nok"))
                                        {
                                            data   = listView1.Items[i].SubItems[2].Text + ", " + listView1.Items[i].Index + 1;
                                            Result = "In your storage, part with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + "\n, already exist in DB.\n\nNothing Done.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            textBox1.SelectAll();
                                            textBox1.Focus();
                                            return;
                                        }
                                    }
                                }

                                //Provjera i spremanje u bazu

                                List <String> allRegions = new List <string>();
                                allRegions = qc.GetAllRegions();

                                int index = resultArrC.FindIndex(resultArrC => resultArrC.Name.Equals(label2.Text));

                                if (resultArrC[index].RegionID != Properties.Settings.Default.OstaliIDRegion &&
                                    resultArrC[index].RegionID != Properties.Settings.Default.TransportIDRegion)
                                {
                                    queryPR   = "Select RegionIDOut from Transport where RegionIDIn = " + WorkingUser.RegionID + " and UsersUserIDIn is NULL";
                                    commandPR = new SqlCommand(queryPR, cnnPR);
                                    commandPR.ExecuteNonQuery();
                                    SqlDataReader dataReader = commandPR.ExecuteReader();
                                    dataReader.Read();

                                    if (dataReader.HasRows)
                                    {
                                        do
                                        {
                                            openedTransactionSenderRegions.Add(dataReader["RegionIDOut"].ToString());
                                        } while (dataReader.Read());
                                        dataReader.Close();
                                    }
                                    else
                                    {
                                        data   = resultArrC[index].RegionID + ", " + Properties.Settings.Default.OstaliIDRegion + ", " + resultArrC[index].RegionID + ", " + Properties.Settings.Default.TransportIDRegion;
                                        Result = "From selected region nothing is sent to you. \n\n Nothing Done.";
                                        lw.LogMe(function, usedQC, data, Result);

                                        Program.SaveStop();
                                        MessageBox.Show(Result);

                                        textBox1.SelectAll();
                                        textBox1.Focus();
                                        return;
                                    }

                                    for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu)
                                    {
                                        //long test = long.Parse(listView1.Items[i].SubItems[2].Text.Substring(4)); //DecoderBB
                                        long test = Decoder.GetFullPartCodeLng(listView1.Items[i].SubItems[2].Text);
                                        if (!resultArrSearchCode.Contains(test.ToString()))
                                        {
                                            data   = test.ToString() + ", " + listView1.Items[i].Index + 1;
                                            Result = "There is no part in 'Sifrarnik' with code, = " + test.ToString() + "\n" + "on position " + (listView1.Items[i].Index + 1) + "  \n\n Nothing Done.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            textBox1.SelectAll();
                                            textBox1.Focus();
                                            return;
                                        }
                                    }

                                    //Provjera da li sam odabrao dobru tvrtku koja salje
                                    Boolean exist = false;
                                    for (int j = 0; j < openedTransactionSenderRegions.Count; j++)
                                    {
                                        if (cmpS.RegionID.ToString().Equals(openedTransactionSenderRegions[j]))
                                        {
                                            exist = true;
                                            break;
                                        }
                                    }

                                    if (!exist)
                                    {
                                        data   = cmpS.RegionID.ToString();
                                        Result = "Please select right company! \n\n Nothing done.";
                                        lw.LogMe(function, usedQC, data, Result);

                                        Program.SaveStop();
                                        MessageBox.Show(Result);

                                        textBox1.SelectAll();
                                        textBox1.Focus();
                                        return;
                                    }

                                    openedOTP = qc.GetAllOpenedOTP(WorkingUser.Username, WorkingUser.Password, WorkingUser.RegionID);
                                    long selectedOTP = 0;

                                    if (openedOTP[0].Equals("nok"))
                                    {
                                        data   = openedOTP[0].ToString();
                                        Result = "There is no opened documents for you!";
                                        lw.LogMe(function, usedQC, data, Result);

                                        Program.SaveStop();
                                        MessageBox.Show(Result);

                                        textBox1.SelectAll();
                                        textBox1.Focus();
                                        return;
                                    }

                                    using (Selector selector = new Selector())
                                    {
                                        selector.SetLabelText          = "Please select receiving document";
                                        selector.SetComboBoxStringList = openedOTP;
                                        selector.ShowDialog();

                                        if (selector.GetOTPValue > 0)
                                        {
                                            selectedOTP = selector.GetOTPValue;
                                        }
                                        else
                                        {
                                            data   = selectedOTP.ToString();
                                            Result = "Please select valid receiving document! \n\n Nothing done.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            textBox1.SelectAll();
                                            textBox1.Focus();
                                            return;
                                        }
                                    }

                                    Part otpParts = new Part();
                                    listOfOtpPartsFromOTP = otpParts.GetListOfPartsOTPParts(selectedOTP);

                                    int     counterLP = listOfOtpPartsFromOTP.Count;
                                    int     counterLV = listView1.Items.Count;
                                    Boolean same      = false;
                                    for (int i = 0; i < counterLP; i++)
                                    {
                                        for (int ii = 0; ii < counterLV; ii++)
                                        {
                                            if (listOfOtpPartsFromOTP[i].CodePartFull == long.Parse(listView1.Items[ii].SubItems[2].Text) &&
                                                listOfOtpPartsFromOTP[i].SN.ToUpper().Equals(listView1.Items[ii].SubItems[3].Text.ToUpper()) &&
                                                listOfOtpPartsFromOTP[i].CN.ToUpper().Equals(listView1.Items[ii].SubItems[4].Text.ToUpper()))
                                            {
                                                same = true;
                                                break;
                                            }
                                            else
                                            {
                                                same = false;
                                                data = listOfOtpPartsFromOTP[i].CodePartFull.ToString() + ", " + long.Parse(listView1.Items[ii].SubItems[2].Text).ToString() + ", " +
                                                       listOfOtpPartsFromOTP[i].SN.ToUpper().Equals(listView1.Items[ii].SubItems[3].Text.ToUpper()).ToString() + ", " + listOfOtpPartsFromOTP[i].CN.ToUpper().Equals(listView1.Items[ii].SubItems[4].Text.ToUpper()).ToString();
                                            }
                                        }
                                        if (!same)
                                        {
                                            break;
                                        }
                                    }

                                    if (!same || counterLP != counterLV)
                                    {
                                        Result = "Receiving document and sending document items do not match ! \n\n Nothing done.";
                                        lw.LogMe(function, usedQC, data, Result);

                                        Program.SaveStop();
                                        MessageBox.Show(Result);

                                        textBox1.SelectAll();
                                        textBox1.Focus();
                                        return;
                                    }

                                    PrimkaNumber = qc.PRIMUnesiUredajeDaSuPrimljeniInnner(WorkingUser.Username, WorkingUser.Password, listOfOtpPartsFromOTP, cmpS.RegionID, cmpR.RegionID, selectedOTP, textBox4.Text);
                                    if (!PrimkaNumber.Equals("nok"))
                                    {
                                        PovijestLog pl    = new PovijestLog();
                                        Boolean     saved = false;
                                        for (int k = 0; k < listOfOtpPartsFromOTP.Count; k++)
                                        {
                                            List <Part> tempPart = new List <Part>();
                                            tempPart.Clear();
                                            tempPart.Add(listOfOtpPartsFromOTP[k]);
                                            if (pl.SaveToPovijestLog(tempPart, DateTime.Now.ToString("dd.MM.yy."), textBox4.Text, cmpS.Name, "", "", "PRIM " + Properties.Settings.Default.ShareDocumentName, tempPart[0].State))
                                            {
                                                saved = true;
                                                Properties.Settings.Default.ShareDocumentName = "";
                                            }
                                            else
                                            {
                                                saved = false;
                                                break;
                                            }
                                        }

                                        if (saved)
                                        {
                                            data   = PrimkaNumber;
                                            Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "'.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            isPrimkaSaved = true;
                                            listView1.Clear();
                                            listView1.View = View.Details;

                                            partListPrint.Clear();
                                            partListPrint.AddRange(listOfOtpPartsFromOTP);
                                            //partListPrint = listOfOtpPartsPrimka;

                                            listView1.Columns.Add("RB");
                                            listView1.Columns.Add("Name");
                                            listView1.Columns.Add("Code");
                                            listView1.Columns.Add("SN");
                                            listView1.Columns.Add("CN");
                                            listView1.Columns.Add("Condition");
                                            textBox4.Clear();
                                        }
                                        else
                                        {
                                            data   = PrimkaNumber;
                                            Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "', but not saved in PL.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            listView1.Clear();
                                            listView1.View = View.Details;

                                            partListPrint.Clear();
                                            partListPrint.AddRange(listOfOtpPartsFromOTP);
                                            //partListPrint = listOfOtpPartsPrimka;

                                            listView1.Columns.Add("RB");
                                            listView1.Columns.Add("Name");
                                            listView1.Columns.Add("Code");
                                            listView1.Columns.Add("SN");
                                            listView1.Columns.Add("CN");
                                            listView1.Columns.Add("Condition");
                                            textBox4.Clear();
                                        }
                                    }
                                    else
                                    {
                                        Result = "Unknown error in QUERYinner.";
                                        lw.LogMe(function, usedQC, data, Result);

                                        Program.SaveStop();
                                        MessageBox.Show(Result);

                                        isPrimkaSaved = false;
                                    }
                                }
                                else if (resultArrC[index].RegionID == Properties.Settings.Default.OstaliIDRegion)
                                {
                                    List <Part> partList     = new List <Part>();
                                    String      napomenaPRIM = napomenaPRIMPrint = textBox4.Text;

                                    for (int i = 0; i < listView1.Items.Count; i++)
                                    {
                                        PartSifrarnik tempSifPart = new PartSifrarnik();
                                        Part          tempPart    = new Part();

                                        //tempSifPart.GetPart(listView1.Items[i].SubItems[2].Text.Substring(4)); //DecoderBB
                                        tempSifPart.GetPart(Decoder.GetFullPartCodeStr(listView1.Items[i].SubItems[2].Text));

                                        tempPart.PartialCode = tempSifPart.FullCode;
                                        tempPart.SN          = listView1.Items[i].SubItems[3].Text;
                                        tempPart.CN          = listView1.Items[i].SubItems[4].Text;
                                        tempPart.DateIn      = DateTime.Now.ToString("dd.MM.yy.");
                                        tempPart.StorageID   = WorkingUser.RegionID;
                                        tempPart.State       = listView1.Items[i].SubItems[5].Text;
                                        //tempPart.CompanyO = listView1.Items[i].SubItems[2].Text.Substring(0, 2); //DecoderBB
                                        tempPart.CompanyO = Decoder.GetOwnerCode(listView1.Items[i].SubItems[2].Text);
                                        //tempPart.CompanyC = listView1.Items[i].SubItems[2].Text.Substring(2, 2); //DecoderBB
                                        tempPart.CompanyC = Decoder.GetCustomerCode(listView1.Items[i].SubItems[2].Text);

                                        partList.Add(tempPart);
                                    }

                                    PrimkaNumber = qc.PRIMUnesiUredajeDaSuPrimljeni(WorkingUser.Username, WorkingUser.Password, partList, WorkingUser.RegionID, cmpS.ID, napomenaPRIM);
                                    if (!PrimkaNumber.Equals("nok"))
                                    {
                                        PovijestLog pl    = new PovijestLog();
                                        Boolean     saved = false;
                                        for (int k = 0; k < partList.Count; k++)
                                        {
                                            List <Part> tempPart = new List <Part>();
                                            tempPart.Clear();
                                            tempPart.Add(partList[k]);
                                            if (pl.SaveToPovijestLog(tempPart, DateTime.Now.ToString("dd.MM.yy."), napomenaPRIM, cmpS.Name, "", "", "PRIM " + Properties.Settings.Default.ShareDocumentName, tempPart[0].State))
                                            {
                                                saved = true;
                                            }
                                            else
                                            {
                                                saved = false;
                                                Properties.Settings.Default.ShareDocumentName = "";
                                                break;
                                            }
                                        }

                                        if (Program.SaveDocumentsPDF)
                                        {
                                            saveToPDF(partList);
                                        }

                                        if (saved)
                                        {
                                            data   = PrimkaNumber;
                                            Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "'.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            partListPrint.Clear();
                                            partListPrint.AddRange(partList);

                                            isPrimkaSaved = true;
                                            listView1.Clear();
                                            listView1.View = View.Details;

                                            listView1.Columns.Add("RB");
                                            listView1.Columns.Add("Name");
                                            listView1.Columns.Add("Code");
                                            listView1.Columns.Add("SN");
                                            listView1.Columns.Add("CN");
                                            listView1.Columns.Add("Condition");
                                            textBox4.Clear();
                                            napomenaPRIMPrint = napomenaPRIM;
                                        }
                                        else
                                        {
                                            data   = PrimkaNumber;
                                            Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "', but not saved in PL.";
                                            lw.LogMe(function, usedQC, data, Result);

                                            Program.SaveStop();
                                            MessageBox.Show(Result);

                                            partListPrint.Clear();
                                            partListPrint.AddRange(partList);

                                            isPrimkaSaved = true;
                                            listView1.Clear();
                                            listView1.View = View.Details;

                                            listView1.Columns.Add("RB");
                                            listView1.Columns.Add("Name");
                                            listView1.Columns.Add("Code");
                                            listView1.Columns.Add("SN");
                                            listView1.Columns.Add("CN");
                                            listView1.Columns.Add("Condition");
                                            textBox4.Clear();
                                            napomenaPRIMPrint = napomenaPRIM;
                                        }
                                    }
                                    else
                                    {
                                        Result = "Unknown error in QUERYinner.";
                                        lw.LogMe(function, usedQC, data, Result);

                                        Program.SaveStop();
                                        MessageBox.Show(Result);

                                        napomenaPRIMPrint = "";
                                        isPrimkaSaved     = false;
                                    }
                                }
                            }
                            cnnPR.Close();
                        }
                    }
                    catch (Exception e1)
                    {
                        Program.SaveStop();

                        new LogWriter(e1);
                        MessageBox.Show(e1.Message);
                        textBox1.SelectAll();
                        textBox1.Focus();
                    }
                }
                this.printPrewBT.Enabled           = isPrimkaSaved;
                this.selectPrinterPrintBtn.Enabled = isPrimkaSaved;
            }
            Program.SaveStop();
        }