Example #1
0
        public static void GenerateBill(int id)
        {
            InitializeWorkbookBill();

            ISheet sheet1 = hssfworkbook.GetSheet("s");


            UniversalEntity ue = new UniversalEntity();
            //UniversalEntity uev = new UniversalEntity();

            UAbonent        ua    = new UAbonent();
            UAbonentDO      uado  = new UAbonentDO();
            UOrder          uo    = new UOrder();
            UOrderDO        uodo  = new UOrderDO();
            UOrderDetailsDO uodDO = new UOrderDetailsDO();

            ue = uado.RetrieveByOrderID(id);
            string header    = string.Empty;
            string actNumber = string.Empty;

            if (ue.Count > 0)
            {
                ua      = (UAbonent)ue[0];
                header += ua.Title + " \nюр адрес: " + ua.Address + " \n№ св. пл. НДС: " + ua.VATPay + " \n№ ИНН: " + ua.INN + " \nтел.: " + ua.Phone;
            }
            ue = uodo.RetrieveUOrderById(id);
            if (ue.Count > 0)
            {
                uo = (UOrder)ue[0];
                sheet1.GetRow(4).GetCell(GetLetterNumber("aj")).SetCellValue(uo.ID);
                sheet1.GetRow(9).GetCell(GetLetterNumber("ai")).SetCellValue(RuDateAndMoneyConverter.DateToTextLongUA(uo.DateIn) + "р.");
            }
            ue = uodDO.RetrieveUOrderDetailsByOrderID(id);
            sheet1.GetRow(16).GetCell(6).SetCellValue(header);



            int    count = ue.Count;
            double sum   = 0;
            int    row   = 20;

            if (count <= 5)
            {
                CustomRetrieverDO crDO = new CustomRetrieverDO();
                ue = crDO.RetrieveUActByOrderID5Low(id);
                if (ue.Count > 0)
                {
                    for (int i = row; i < ue.Count + row; i++)
                    {
                        ArrayList al = (ArrayList)ue[i - row];

                        sheet1.GetRow(i).GetCell(GetLetterNumber("a")).SetCellValue(string.Format("Определения метрологических характеристик водомера  D{0}, {1}, {2}", al[0].ToString(), al[1].ToString(), al[2].ToString()));
                        sheet1.GetRow(i).GetCell(GetLetterNumber("ad")).SetCellValue("шт.");
                        sheet1.GetRow(i).GetCell(GetLetterNumber("aj")).SetCellValue(al[4].ToString());
                        sheet1.GetRow(i).GetCell(GetLetterNumber("ap")).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));
                        sheet1.GetRow(i).GetCell(GetLetterNumber("av")).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));
                        sum += Convert.ToDouble(al[3]);
                    }
                }
            }
            else
            {
                CustomRetrieverDO crDO = new CustomRetrieverDO();
                ue = crDO.RetrieveUActByOrderID5High(id);
                if (ue.Count > 0)
                {
                    for (int i = row; i < ue.Count + row; i++)
                    {
                        ArrayList al = (ArrayList)ue[i - row];
                        //FOrderDetailsAct u = (FOrderDetailsAct)fodal[i - row];

                        sheet1.GetRow(i).GetCell(GetLetterNumber("a")).SetCellValue(string.Format("Определения метрологических характеристик водомера  D{0}", al[0].ToString()));
                        sheet1.GetRow(i).GetCell(GetLetterNumber("ad")).SetCellValue("шт.");
                        sheet1.GetRow(i).GetCell(GetLetterNumber("aj")).SetCellValue(al[3].ToString());
                        sheet1.GetRow(i).GetCell(GetLetterNumber("ap")).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));
                        sheet1.GetRow(i).GetCell(GetLetterNumber("av")).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));

                        sum += Convert.ToDouble(al[2]);
                    }
                }
            }

            /*int row = 20;
             * double sum = 0;
             *
             *
             *
             *
             *
             * if (ue.Count > 0)
             * {
             *  for (int i = row; i < ue.Count + row; i++)
             *  {
             *      UOrderDetails u = (UOrderDetails)ue[i - row];
             *
             *      sheet1.GetRow(i).GetCell(GetLetterNumber("a")).SetCellValue("Определения метрологических характеристик водомера ");
             *      sheet1.GetRow(i).GetCell(GetLetterNumber("ad")).SetCellValue("шт.");
             *      sheet1.GetRow(i).GetCell(GetLetterNumber("aj")).SetCellValue("1");
             *      sheet1.GetRow(i).GetCell(GetLetterNumber("ap")).SetCellValue(u.Price.ToString("0.00"));
             *      sheet1.GetRow(i).GetCell(GetLetterNumber("av")).SetCellValue(u.Price.ToString("0.00"));
             *      sum += u.Price;
             *  }
             * }*/
            sheet1.GetRow(31).GetCell(GetLetterNumber("av")).SetCellValue(sum.ToString("0.00"));
            sheet1.GetRow(32).GetCell(GetLetterNumber("av")).SetCellValue(Utilities.GetVAT(sum).ToString("0.00"));
            sheet1.GetRow(33).GetCell(GetLetterNumber("av")).SetCellValue((sum + Utilities.GetVAT(sum)).ToString("0.00"));
            sheet1.GetRow(35).GetCell(GetLetterNumber("a")).SetCellValue("Загальна сума, що підлягає оплаті: " + UADateAndMoneyConverter.CurrencyToTxt((sum + Utilities.GetVAT(sum)), true));
            //Загальна сума, що підлягає оплаті


            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;

            WriteToFileB();
        }
Example #2
0
        //Генерация договора
        protected void btContract_Click(object sender, EventArgs e)
        {
            UniversalEntity ue   = new UniversalEntity();
            UniversalEntity uev  = new UniversalEntity();
            int             id   = Convert.ToInt32(hfODID.Value);
            UAbonent        ua   = new UAbonent();
            UAbonentDO      uado = new UAbonentDO();

            ue = uado.RetrieveByOrderID(id);
            UOrderDetailsDO uoddo = new UOrderDetailsDO();
            VodomerTypeDO   vtdo  = new VodomerTypeDO();
            VodomerType     vt;
            UOrderDetails   uod;

            if (ue.Count > 0)
            {
                double sum     = 0;
                double sumvat  = 0;
                string vodomer = string.Empty;
                ua = (UAbonent)ue[0];
                ue = uoddo.RetrieveUOrderDetailsByOrderID(id);
                if (ue.Count > 0)
                {
                    for (int i = 0; i < ue.Count; i++)
                    {
                        uod     = (UOrderDetails)ue[i];
                        sum    += uod.GetPriceWithVAT();
                        sumvat += uod.GetPriceVAT();
                        uev     = vtdo.RetrieveVodomerTypeByVodomerId(uod.VodomerID);
                        if (uev.Count > 0)
                        {
                            for (int j = 0; j < uev.Count; j++)
                            {
                                vt       = (VodomerType)uev[j];
                                vodomer += "Поверить " + vt.Description + " Ø " + vt.Diameter.ToString() + " мм  в количестве 1 шт.,  ";
                            }
                        }
                    }
                }
                UOrder   uo   = new UOrder();
                UOrderDO uoDO = new UOrderDO();
                ue = uoDO.RetrieveUOrderById(id);
                if (ue.Count > 0)
                {
                    uo = (UOrder)ue[0];
                }
                if (ua.IsBudget)
                {
                    //Для бюджетных организаций
                    using (DocX document = DocX.Load(Request.MapPath("~\\Templates/noncommerce.docx")))
                    {
                        //DocXExtender.ReplaceFormatedText(document, "DDD", "дата");
                        document.ReplaceText("NNN", uo.ID.ToString(), false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("DATE", RuDateAndMoneyConverter.DateToTextLong(uo.DateIn) + " г.", false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("TITLE", ua.Title, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("VODOMER", vodomer, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("SUM", RuDateAndMoneyConverter.CurrencyToTxt(sum, true), false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("NDS", RuDateAndMoneyConverter.CurrencyToTxt(sumvat, true), false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("SSS", (sum).ToString("0.00") + " грн", false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("RS", ua.RS, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("BANK", ua.Bank, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("MFO", ua.MFO, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("OKPO", ua.OKPO, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("ADDRESS", ua.Address, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("FACE", ua.ContactFace, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("CAUSE", ua.Cause, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("PHONE", ua.Phone, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        //TAXTYPE
                        document.ReplaceText("TAXTYPE", ua.TaxType, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                        //VODOMER
                        document.SaveAs(Request.MapPath("~\\Templates/outnoncommerce.docx"));
                        litScript.Text = "<iframe style=\"display:none;\" src=\"../GetDocument.ashx?Commerce=1\"></iframe>";
                    }
                }
                else
                {
                    //для небюджетных организаций
                    using (DocX document = DocX.Load(Request.MapPath("~\\Templates/commerce.docx")))
                    {
                        //DocXExtender.ReplaceFormatedText(document, "DDD", "дата");
                        document.ReplaceText("NNN", uo.ID.ToString(), false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("DATE", RuDateAndMoneyConverter.DateToTextLong(uo.DateIn) + " г.", false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("TITLE", ua.Title, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("VODOMER", vodomer, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("SUM", RuDateAndMoneyConverter.CurrencyToTxt(sum, true), false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("NDS", RuDateAndMoneyConverter.CurrencyToTxt(sumvat, true), false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("RS", ua.RS, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("BANK", ua.Bank, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("MFO", ua.MFO, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("OKPO", ua.OKPO, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("ADDRESS", ua.Address, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("FACE", ua.ContactFace, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("CAUSE", ua.Cause, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("PHONE", ua.Phone, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        document.ReplaceText("TAXTYPE", ua.TaxType, false, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                        //VODOMER
                        document.SaveAs(Request.MapPath("~\\Templates/outcommerce.docx"));
                        litScript.Text = "<iframe style=\"display:none;\" src=\"../GetDocument.ashx?Commerce=0\"></iframe>";
                    }
                }
            }
        }
Example #3
0
        public static void GenerateFAct(int id)
        {
            UniversalEntity ue         = new UniversalEntity();
            string          header     = string.Empty;
            string          actNumber  = string.Empty;
            string          actNumber2 = string.Empty;

            FAbonentDO faDO = new FAbonentDO();

            ue = faDO.RetrieveByOrderID(id);
            if (ue.Count > 0)
            {
                FAbonent fa = (FAbonent)ue[0];
                header += fa.Surname + " " + fa.FirstName + " " + fa.LastName + " \nадрес: " + fa.Address + "\nтел.: " + fa.Phone;
            }

            FOrder          fo    = new FOrder();
            FOrderDO        foDO  = new FOrderDO();
            FOrderDetailsDO fodDO = new FOrderDetailsDO();

            ue = foDO.RetrieveFOrderById(id);
            if (ue.Count > 0)
            {
                fo         = (FOrder)ue[0];
                actNumber  = "  г. Донецк            АКТ № " + fo.Prefix + fo.ID + " от " + RuDateAndMoneyConverter.DateToTextLong(fo.DateIn) + " г.";
                actNumber2 = "                             по договору (письму) №  " + fo.Prefix + fo.ID + " от " + RuDateAndMoneyConverter.DateToTextLong(fo.DateIn) + " г.";
            }

            ue = fodDO.RetrieveFOrderDetailsByOrderID(id);

            InitializeWorkbookFAct(); //InitializeWorkbook();
            ISheet sheet1 = hssfworkbook.GetSheet("s");

            //create cell on rows, since rows do already exist,it's not necessary to create rows again.
            sheet1.GetRow(2).GetCell(3).SetCellValue(header);
            sheet1.GetRow(32).GetCell(3).SetCellValue(header);
            sheet1.GetRow(9).GetCell(0).SetCellValue(actNumber);
            sheet1.GetRow(39).GetCell(0).SetCellValue(actNumber);
            sheet1.GetRow(11).GetCell(0).SetCellValue(actNumber2);
            sheet1.GetRow(41).GetCell(0).SetCellValue(actNumber2);

            int    rowC = 44;
            int    row  = 14;
            double sum  = 0;

            int count = ue.Count;

            if (count <= 5)
            {
                CustomRetrieverDO crDO = new CustomRetrieverDO();
                ue = crDO.RetrieveFActByOrderID5Low(id);
                if (ue.Count > 0)
                {
                    for (int i = row; i < ue.Count + row; i++)
                    {
                        ArrayList al = (ArrayList)ue[i - row];
                        //FOrderDetailsAct u = (FOrderDetailsAct)fodal[i - row];

                        sheet1.GetRow(i).GetCell(0).SetCellValue(i - row + 1);
                        sheet1.GetRow(i).GetCell(1).SetCellValue(string.Format("Определения метрологических характеристик водомера  D{0}, {1}, {2}", al[0].ToString(), al[1].ToString(), al[2].ToString()));
                        sheet1.GetRow(i).GetCell(2).SetCellValue("калькуляция");
                        sheet1.GetRow(i).GetCell(3).SetCellValue("шт.");
                        sheet1.GetRow(i).GetCell(4).SetCellValue(al[4].ToString());
                        sheet1.GetRow(i).GetCell(5).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));
                        sheet1.GetRow(i).GetCell(6).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));


                        sheet1.GetRow(rowC).GetCell(0).SetCellValue(i - row + 1);
                        sheet1.GetRow(rowC).GetCell(1).SetCellValue(string.Format("Определения метрологических характеристик водомера  D{0}, {1}, {2}", al[0].ToString(), al[1].ToString(), al[2].ToString()));
                        sheet1.GetRow(rowC).GetCell(2).SetCellValue("калькуляция");
                        sheet1.GetRow(rowC).GetCell(3).SetCellValue("шт.");
                        sheet1.GetRow(rowC).GetCell(4).SetCellValue(al[4].ToString());
                        sheet1.GetRow(rowC).GetCell(5).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));
                        sheet1.GetRow(rowC).GetCell(6).SetCellValue(Convert.ToDouble(al[3]).ToString("0.00"));

                        sum += Convert.ToDouble(al[3]);
                        rowC++;
                    }
                }
            }
            else
            {
                CustomRetrieverDO crDO = new CustomRetrieverDO();
                ue = crDO.RetrieveFActByOrderID5High(id);
                if (ue.Count > 0)
                {
                    for (int i = row; i < ue.Count + row; i++)
                    {
                        ArrayList al = (ArrayList)ue[i - row];
                        //FOrderDetailsAct u = (FOrderDetailsAct)fodal[i - row];

                        sheet1.GetRow(i).GetCell(0).SetCellValue(i - row + 1);
                        sheet1.GetRow(i).GetCell(1).SetCellValue(string.Format("Определения метрологических характеристик водомера  D{0}", al[0].ToString()));
                        sheet1.GetRow(i).GetCell(2).SetCellValue("калькуляция");
                        sheet1.GetRow(i).GetCell(3).SetCellValue("шт.");
                        sheet1.GetRow(i).GetCell(4).SetCellValue(al[3].ToString());
                        sheet1.GetRow(i).GetCell(5).SetCellValue(Convert.ToDouble(al[1]).ToString("0.00"));
                        sheet1.GetRow(i).GetCell(6).SetCellValue(Convert.ToDouble(al[2]).ToString("0.00"));


                        sheet1.GetRow(rowC).GetCell(0).SetCellValue(i - row + 1);
                        sheet1.GetRow(rowC).GetCell(1).SetCellValue(string.Format("Определения метрологических характеристик водомера  D{0}", al[0].ToString()));
                        sheet1.GetRow(rowC).GetCell(2).SetCellValue("калькуляция");
                        sheet1.GetRow(rowC).GetCell(3).SetCellValue("шт.");
                        sheet1.GetRow(rowC).GetCell(4).SetCellValue(al[3].ToString());
                        sheet1.GetRow(rowC).GetCell(5).SetCellValue(Convert.ToDouble(al[1]).ToString("0.00"));
                        sheet1.GetRow(rowC).GetCell(6).SetCellValue(Convert.ToDouble(al[2]).ToString("0.00"));

                        sum += Convert.ToDouble(al[2]);
                        rowC++;
                    }
                }
            }



            sheet1.GetRow(19).GetCell(6).SetCellValue(sum.ToString("0.00"));
            sheet1.GetRow(20).GetCell(6).SetCellValue((sum / 100 * 20).ToString("0.00"));
            sheet1.GetRow(21).GetCell(6).SetCellValue((sum + (sum / 100 * 20)).ToString("0.00"));

            sheet1.GetRow(49).GetCell(6).SetCellValue(sum.ToString("0.00"));
            sheet1.GetRow(50).GetCell(6).SetCellValue((sum / 100 * 20).ToString("0.00"));
            sheet1.GetRow(51).GetCell(6).SetCellValue((sum + (sum / 100 * 20)).ToString("0.00"));

            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;

            WriteToFileF();
        }