private Dictionary<String, Dictionary<String, String>[]> createDictionary4FirstSection(string offerRegNumber, string budgetFundingText, 
            TAuction auction, Lot4Offer[] lots, SecurityDoc[] securityDocs, File[] files)
        {
            Dictionary<String, Dictionary<String, String>[]> dict = new Dictionary<string, Dictionary<string, string>[]>();

            //lots
            Dictionary<String, String>[] lotsDict = new Dictionary<string, string>[lots.Length];
            for (int i = 0; i < lots.Length; i++)
            {
                lotsDict[i] = new Dictionary<string, string>();

                lotsDict[i].Add("lotNumber", lots[i].NumLot.ToString());
                //TODO clarify
                lotsDict[i].Add("lotShortName", "");

                string okrb = "";
                for (int j = 0; j < lots[i].OKRB.Length; j++)
                {
                    okrb += lots[i].OKRB[j].OKRBCode;
                    if (j < lots[i].OKRB.Length - 1)
                    {
                        okrb += ", ";
                    }
                }
                lotsDict[i].Add("lotOKRB", okrb);

                lotsDict[i].Add("lotDescr", lots[i].Description);
                lotsDict[i].Add("lotValue", double.Parse(lots[i].Value.Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture).ToString("#,##.####") + " " + lots[i].EdIzm);
                lotsDict[i].Add("lotCalc", lots[i].CalcMethod);
                lotsDict[i].Add("lotDeliveryPlace", lots[i].Place);
                lotsDict[i].Add("lotDeliveryTime", lots[i].Time);
                lotsDict[i].Add("lotPrice", double.Parse(lots[i].Price.Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture).ToString("#,##.####"));
                lotsDict[i].Add("lotCurrency", lots[i].Currency);
                lotsDict[i].Add("lotOther", lots[i].OtherInfo);
                lotsDict[i].Add("offerExpirationDate", DateTimeUtils.DoubleToDateTime(auction.AuctionInfo.ExpiryOfferDate).ToString("dd.MM.yyyy"));
                lotsDict[i].Add("correction", lots[i].Correction + " %");
                lotsDict[i].Add("foundingCorrection", lots[i].FoundingCorrection);
            }
            dict.Add("repeatingUnitLot", lotsDict);

            //security docs
            Dictionary<String, String>[] securityDocsDict = new Dictionary<string, string>[securityDocs == null ? 0 : securityDocs.Length];
            for (int i = 0; i < securityDocsDict.Length; i++)
            {
                securityDocsDict[i] = new Dictionary<string, string>();

                securityDocsDict[i].Add("securityView", securityDocs[i].SecurityView);
                securityDocsDict[i].Add("docNumber", securityDocs[i].DocNumber);
                securityDocsDict[i].Add("docDate", securityDocs[i].DocDate);
                securityDocsDict[i].Add("securityValue", double.Parse(securityDocs[i].SecurityValue,
                    System.Globalization.CultureInfo.InvariantCulture).ToString("#,##.####") + " " + securityDocs[i].Currency);
                securityDocsDict[i].Add("securityPeriod", securityDocs[i].SecurityPeriod);
            }
            dict.Add("repeatingUnitSecurity", securityDocsDict);

            //files
            Dictionary<String, String>[] filesDict = new Dictionary<string, string>[files == null ? 0 : files.Length];
            for (int i = 0; i < filesDict.Length; i++)
            {
                filesDict[i] = new Dictionary<string, string>();
                filesDict[i].Add("docName", files[i].DocName);
            }
            dict.Add("repeatingUnitDoc", filesDict);

            //other
            Dictionary<String, String>[] other = new Dictionary<string, string>[1];
            other[0] = new Dictionary<string, string>();
            other[0].Add("offerNumber", offerRegNumber);
            other[0].Add("siteAddress", auction.AuctionHeader.PurchaseSite);
            other[0].Add("regNumber", auction.AuctionHeader.AuctionRegNumber);
            other[0].Add("shortName", auction.AuctionHeader.PurchaseName);
            other[0].Add("budgetOrg", budgetFundingText);
            other[0].Add("securityValue", auction.AuctionInfo.SecurityPercent.ToString());
            dict.Add("other", other);

            return dict;
        }
        public ActionResult AddOffer(TOfferInitialData offerInitialData, TAuction auction, Lot4Offer[] lots,
            SecurityDoc[] securityDocs, String content1, String signature1, File[] files1,
            Contact[] contatcs, String content2, String signature2, File[] files2)
        {
            TOffer offer = new TOffer();

            //fill offer info
            TOfferInfo offerInfo = new TOfferInfo();
            offerInfo.OfferRegNumber = offerInitialData.OfferRegNumber;
            offerInfo.ExpiryOfferDate = auction.AuctionInfo.ExpiryOfferDate;
            offerInfo.SecurityPercent = auction.AuctionInfo.SecurityPercent;
            offerInfo.SubjectName = auction.AuctionInfo.SubjectName;
            offer.OfferInfo = offerInfo;

            offer.AuctionHeader = auction.AuctionHeader;
            offer.AuctionID = auction.AuctionID;
            offer.AuctionStatusText = auction.AuctionStatusText;
            offer.BudgetFunding = offerInitialData.BudgetFunding;
            offer.BudgetFundingText = offerInitialData.BudgetFundingText;
            //offer.ServiceFeeFlag =
            //offer.ServiceFeeText =
            offer.Participant = offerInitialData.Participant;

            //fill lots data
            TOfferLotInfo[] offerLots = new TOfferLotInfo[lots == null ? 0 : lots.Length];
            for (int i = 0; i < offerLots.Length; i++)
            {
                offerLots[i] = new TOfferLotInfo();
                offerLots[i].AddInfo = lots[i].OtherInfo;
                //offerLots[i].AuctionLotStatusText =
                offerLots[i].AgreementConsent = 1;
                offerLots[i].Currency = lots[i].CurrencyCode;
                offerLots[i].CurrencyAbb = lots[i].Currency;
                offerLots[i].DeliveryDate = lots[i].Time;
                offerLots[i].DeliveryPlace = lots[i].Place;
                offerLots[i].Description = lots[i].Description;
                offerLots[i].EdIzm = lots[i].EdIzmCode;
                offerLots[i].EdIzmAbb = lots[i].EdIzm;
                offerLots[i].FundingSource = int.Parse(lots[i].FinanceSourceCode);
                offerLots[i].FundingSourceText = lots[i].FinanceSource;
                offerLots[i].LotID = lots[i].LotID;
                offerLots[i].LotVolume = string.IsNullOrEmpty(lots[i].Value) ? 0 : double.Parse(lots[i].Value.Trim().Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
                offerLots[i].NumLot = lots[i].NumLot;
                TOKRBRec[] okrb = new TOKRBRec[lots[i].OKRB.Length];
                for (int j = 0; j < lots[i].OKRB.Length; j++)
                {
                    TOKRBRec okrbRec = new TOKRBRec();
                    okrbRec.OKRBCode = lots[i].OKRB[j].OKRBCode;
                    okrbRec.OKRBID = int.Parse(lots[i].OKRB[j].OKRBID);
                    okrbRec.OKRBName = lots[i].OKRB[j].OKRBName;
                    okrb[j] = okrbRec;
                }
                offerLots[i].OKRBList = okrb;
                offerLots[i].PrefPercent = string.IsNullOrEmpty(lots[i].Correction) ? 0 : double.Parse(lots[i].Correction.Trim().Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
                offerLots[i].PrefReason = lots[i].FoundingCorrection;
                offerLots[i].SecurityValue = auction.AuctionInfo.SecurityPercent;
                offerLots[i].StartPrice = string.IsNullOrEmpty(lots[i].Price) ? 0 : double.Parse(lots[i].Price.Trim().Replace(" ", ""), System.Globalization.CultureInfo.InvariantCulture);
                offerLots[i].VolumeMethod = lots[i].CalcMethod;
            }
            offer.Lots = offerLots;

            //fill contact data
            TContactPerson[] tContatcs=new TContactPerson[contatcs==null?0:contatcs.Length];
            for (int i = 0; i < contatcs.Length; i++)
            {
                tContatcs[i] = new TContactPerson();
                tContatcs[i].FIO = contatcs[i].FIO;
                tContatcs[i].Phone = contatcs[i].Phones;
                tContatcs[i].Fax = contatcs[i].Fax;
                tContatcs[i].Email = contatcs[i].Email;
                tContatcs[i].AddInfo = contatcs[i].OtherInfo;
            }
            offer.ContactPersons = tContatcs;

            //fill security docs data
            TSecurityDoc[] tSecurityDocs = new TSecurityDoc[securityDocs==null?0:securityDocs.Length];
            for (int i = 0; i < tSecurityDocs.Length; i++)
            {
                tSecurityDocs[i] = new TSecurityDoc();
                //tSecurityDocs[i].ConfirmDate = ...;
                tSecurityDocs[i].Currency = securityDocs[i].CurrencyCode;
                tSecurityDocs[i].CurrencyAbb = securityDocs[i].Currency;
                tSecurityDocs[i].DocDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(securityDocs[i].DocDate.Trim().Replace(" ", string.Empty)));
                tSecurityDocs[i].DocNum = securityDocs[i].DocNumber;
                tSecurityDocs[i].DocTypeText = securityDocs[i].SecurityView;
                tSecurityDocs[i].ExpiryDate = DateTimeUtils.DateTimeToDouble(DateTime.Parse(securityDocs[i].SecurityPeriod.Trim().Replace(" ", string.Empty)));
                tSecurityDocs[i].SecuritySum = string.IsNullOrEmpty(securityDocs[i].SecurityValue) ? 0 : double.Parse(securityDocs[i].SecurityValue, System.Globalization.CultureInfo.InvariantCulture);
            }
            offer.SecurityDocs = tSecurityDocs;

            GovernmentPurchases.WebReference.TEDContent eContent1 = new GovernmentPurchases.WebReference.TEDContent();
            eContent1.Content = content1;
            eContent1.Signature = signature1;

            GovernmentPurchases.WebReference.TEDContent eContent2 = new GovernmentPurchases.WebReference.TEDContent();
            eContent2.Content = content2;
            eContent2.Signature = signature2;

            TAuthHeader header = new TAuthHeader();
            header.SessionID = (String)Session["sessionID"];
            header.SessionKey = (String)Session["sessionKey"];
            client.TAuthHeaderValue = header;

            int offerID = new int();
            client.AddOffer(offer, eContent1, eContent2, ref offerID);

            //upload files
            GovernmentPurchases.IUploadFiles.IUploadFilesservice fileClient = new GovernmentPurchases.IUploadFiles.IUploadFilesservice();
            //upload I section files
            if (files1 != null)
            {
                GovernmentPurchases.IUploadFiles.TEDocument document = new GovernmentPurchases.IUploadFiles.TEDocument();
                GovernmentPurchases.IUploadFiles.TEDContent cont = new GovernmentPurchases.IUploadFiles.TEDContent();

                for (int i = 0; i < files1.Length; i++)
                {
                    document.IDParent = offerID;
                    document.FileName = files1[i].FileName;
                    document.NameDocument = files1[i].DocName;
                    document.TypeDocument = files1[i].DocType;

                    cont.Content = files1[i].Content;
                    cont.Signature = files1[i].Signature;

                    int DocID = new int();
                    fileClient.AddEDoc((String)Session["sessionID"], (String)Session["sessionKey"], C_LINK_OFFERS, document, cont, ref DocID);
                }
            }
            //upload II section files
            if (files2 != null)
            {
                GovernmentPurchases.IUploadFiles.TEDocument document = new GovernmentPurchases.IUploadFiles.TEDocument();
                GovernmentPurchases.IUploadFiles.TEDContent cont = new GovernmentPurchases.IUploadFiles.TEDContent();

                for (int i = 0; i < files2.Length; i++)
                {
                    document.IDParent = offerID;
                    document.FileName = files2[i].FileName;
                    document.NameDocument = files2[i].DocName;
                    document.TypeDocument = files2[i].DocType;

                    cont.Content = files2[i].Content;
                    cont.Signature = files2[i].Signature;

                    int DocID = new int();
                    fileClient.AddEDoc((String)Session["sessionID"], (String)Session["sessionKey"], C_LINK_OFFERS, document, cont, ref DocID);
                }
            }

            AppLogger.Info(Session, "AddOffer: " + offerID);

            return Json(true);
        }
        public ActionResult GetOfferJSON(int id)
        {
            TOffer offer = new TOffer();

            TAuthHeader header = new TAuthHeader();
            header.SessionID = (String)Session["sessionID"];
            header.SessionKey = (String)Session["sessionKey"];
            client.TAuthHeaderValue = header;

            client.GetOfferInfo(id, ref offer);

            SecurityDoc[] securityDocs = new SecurityDoc[offer.SecurityDocs.Length];
            for (int i = 0; i < offer.SecurityDocs.Length; i++)
            {
                securityDocs[i] = new SecurityDoc();
                securityDocs[i].SecurityView = offer.SecurityDocs[i].DocTypeText;
                securityDocs[i].DocNumber = offer.SecurityDocs[i].DocNum;
                securityDocs[i].DocDate = DateTimeUtils.DoubleToDateTime(offer.SecurityDocs[i].DocDate).ToString("dd.MM.yyyy");
                securityDocs[i].SecurityValue = offer.SecurityDocs[i].SecuritySum.ToString();
                securityDocs[i].Currency = offer.SecurityDocs[i].CurrencyAbb;
                securityDocs[i].CurrencyCode = offer.SecurityDocs[i].Currency;
                securityDocs[i].SecurityPeriod = DateTimeUtils.DoubleToDateTime(offer.SecurityDocs[i].ExpiryDate).ToString("dd.MM.yyyy");
            }

            OfferStruc o;
            o.offer = offer;
            o.securityDocs = securityDocs;

            return Json(o);
        }
        public ActionResult GenerateRTFOffer4FirstSection(string offerRegNumber, string budgetFundingText, TAuction auction, Lot4Offer[] lots, SecurityDoc[] securityDocs, File[] files)
        {
            Dictionary<String, Dictionary<String, String>[]> dict = createDictionary4FirstSection(offerRegNumber, budgetFundingText, auction, lots, securityDocs, files);
            string text = TemplatesUtils.generateDocument(Server.MapPath("~") + "Content/static/templates/Offer Prt 1_19032012.rtf", dict);

            return Json(text);
        }