| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097 |
- using System;
- using System.Collections.Generic;
- //using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using Aspose.Words;
- using Aspose.Words.Saving;
- using DocumentFormat.OpenXml.Packaging;
- using Microsoft.AspNetCore.Mvc;
- using Spire.Doc;
- using SuperCms.Models;
- using Syncfusion.DocIO;
- using Syncfusion.DocIO.DLS;
- using Syncfusion.Drawing;
- using OutlineLevel = Syncfusion.DocIO.OutlineLevel;
- using System.IO;
- using System.Globalization;
- using Syncfusion.XlsIO;
- using System.Net.Http;
- using System.Net;
- using System.Text.RegularExpressions;
- namespace SuperCms.Controllers
- {
- public class UtilsController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- public static string[] validformats = new[] {
- "MM/dd/yyyy",
- "yyyy/MM/dd",
- "dd/MM/yyyy HH:mm:ss",
- "MM/dd/yyyy HH:mm:ss",
- "MM/dd/yyyy hh:mm tt",
- "yyyy-MM-dd HH:mm:ss, fff",
- "yyyy-MM-ddTHH:mm:ss",
- "yyyy-MM-ddTHH:mm",
- "yyyy-MM-ddTHH:mm:ss.fff",
- "yyyy-MM-dd",
- "HH:mm:ss","HH:mm"};
- public static String convertLargeNumberToString(int remain, String resString)
- {
- int result, phanDu;
- if (remain > 1000)
- {
- result = remain / 1000;
- phanDu = remain - result * 1000;
- if (resString == "")
- {
- return convertLargeNumberToString(phanDu, resString + "." + phanDu);
- }
- return convertLargeNumberToString(phanDu, resString + ".");
- }
- else
- {
- return resString + "." + remain.ToString();
- }
- }
- public static string RandomString(int size, bool lowerCase)
- {
- StringBuilder builder = new StringBuilder();
- Random random = new Random();
- char ch;
- for (int i = 0; i < size; i++)
- {
- ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
- builder.Append(ch);
- }
- if (lowerCase)
- return builder.ToString().ToLower();
- return builder.ToString();
- }
- public class Constant
- {
- public const String SERVICE_ID = "3";
- public const String PARENT_ID = "-1";
- public const String NUMBER_ROW_ON_PAGE = "10";
- public const String GET_ALL = "-1";
- //
- public const String SUCCESS = "0";
- public const String ERROR = "-1";
- public const String BOTS = "1";
- public const String GROUPS = "2";
- public const String SCHEDULES = "3";
- public const String CONFIGS = "4";
- public const String SENDMAIL = "5";
- public const String SERVICE_CONFIG = "6";
- public const int MAX_SCHEDULE_STATUS = 5;
- public const int MAX_GROUP_STATUS = 2;
- public const int MAX_BOT_STATUS = 1;
- public const int MAX_WARNING_STATUS = 2;
- public const String DISABLE = "0";
- public const String ENABLE = "1";
- public const String MONEY_GET = "0";
- public const String SUBS_GET = "1";
- public const int MAX_GET = 2;
- public const int MAX_TABLE = 5;
- public const String ONLY_REVEUNUE = "0";
- public const String ALL_REVEUNUE = "1";
- public const int MAX_FILE = 2;
- public const String PAYMENT_FILE = "0";
- public const String INVOICE_FILE = "1";
- public const String SHOW_FILE = "1";
- public const String SAVE_FILE = "2";
- public const String DISABLE_GET_DATA = "0";
- public const String ENABLE_GET_DATA_AND_WARNING = "1";
- public const String ENABLE_GET_DATA_AND_NOT_WARNING = "2";
- }
- public static String convertNameTable(String tableType)
- {
- switch (tableType)
- {
- case "1": return "Cấu hình người gửi";
- case "2": return "Cấu hình người nhận";
- case "3": return "Cấu hình lập lịch gửi";
- case "4": return "Cấu hình configuration";
- case "5": return "Cấu hình gửi email";
- case "6": return "Cấu hình thêm mới dịch vụ";
- default: return "NULL";
- }
- }
- public static String convertNameTypeGet(String typeGet)
- {
- switch (typeGet)
- {
- case "0": return "Money Report";
- case "1": return "Subscribers Report";
- default: return "NULL";
- }
- }
- public static String convertScheduleStatus(int status)
- {
- switch (status)
- {
- case 0: return "Disable";
- case 1: return "Reminder one time";
- case 2: return "Reminder hour by hour";
- case 3: return "Reminder day by day";
- case 4: return "Reminder week by week";
- case 5: return "Reminder month by month";
- default: return "NULL";
- }
- }
- public static String convertBotStatus(int status)
- {
- switch (status)
- {
- case 0: return "Disable";
- case 1: return "Get and warning";
- case 2: return "Get and not warning";
- default: return "NULL";
- }
- }
- public static String convertServiceState(int state)
- {
- switch (state)
- {
- case 0: return "Không";
- case 1: return "Có";
- default: return "NULL";
- }
- }
- public static String convertGroupStatus(int status)
- {
- switch (status)
- {
- case 0: return "Disable";
- case 1: return "Communication";
- case 2: return "Alarm";
- default: return "NULL";
- }
- }
- public static String convertSendMailStatus(int status)
- {
- switch (status)
- {
- case 0: return "Disable";
- case 1: return "Enable";
- default: return "NULL";
- }
- }
- public static string ConvertListType(String type)
- {
- switch (type)
- {
- case "0": return "Payment file";
- case "1": return "Invoice file";
- default: return type + " Unknown";
- }
- }
- public static String ReadDocFileToHtml()
- {
- String html = System.IO.File.ReadAllText("./resources/payment_code_all.html");
- return html;
- }
- public static bool InvoiceNatcomInterlandDumpt(Contract contract)
- {
- try
- {
- string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
- "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
- DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
- CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- // Creating a new document.
- WordDocument document = new WordDocument();
- // Setting document page margins.
- MarginsF pagemargins = new MarginsF();
- pagemargins.Bottom = 20;
- pagemargins.Top = 20;
- pagemargins.Left = 75;
- pagemargins.Right = 75;
- // Assigning document page margins to the current section.
- IWSection section = document.AddSection();
- section.PageSetup.Margins = pagemargins;
- section.AddParagraph();
- IWTable table = section.AddTable();
- int rowNum = 7, columnNum = 2;
- RowFormat format = new RowFormat();
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- float tableWidth = table.Width;
- //table.TableFormat.BackColor = Color.FromArgb(192, 192, 192);
- table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[0].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[2].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[2].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[4].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[4].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.5 : tableWidth * 0.5);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- if (i == 0)
- {
- if (j == 6)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- else if (j == 1 || j == 2 || j == 5 || j == 4)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- else
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- }
- else if (i == 1)
- {
- if (j == 6)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- else if (j == 1 || j == 2 || j == 5 || j == 4)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
- }
- else
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- }
- }
- }
- }
- table.ApplyHorizontalMerge(0, 0, 1);
- IWParagraph para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- IWTextRange textRange = para.AppendText("COMMERCIAL INVOICE");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 16;
- textRange.CharacterFormat.Bold = true;
- //para = table[0, 0].AddParagraph();
- //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- //textRange = para.AppendText("No: " + convertTime.ToString("ddMMyyyy") + "-" + contract.id);
- //textRange.CharacterFormat.FontName = "Times New Roman";
- //textRange.CharacterFormat.FontSize = 13;
- //textRange.CharacterFormat.Bold = true;
- para = table[0, 0].AddParagraph();
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("DATE OF EXPORT");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(convertTime.ToString("MMMM/yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 0].AddParagraph();
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("INVOICE NUMBER: " + convertTime.ToString("MM") + contract.id + "/" + convertTime.ToString("yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- //para = table[1, 1].AddParagraph();
- //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- //String d1 = (int.Parse(contract.id) < 10 ? "0" + contract.id : contract.id) + "/VTL-" + contract.syntaxConpany + "/VAS/" + convertTime.ToString("yyyy");
- //textRange = para.AppendText(convertTime.ToString("MM") + contract.id + "/" + convertTime.ToString("yyyy"));
- //textRange.CharacterFormat.FontName = "Times New Roman";
- //textRange.CharacterFormat.FontSize = 11;
- //textRange.CharacterFormat.Bold = false;
- para = table[1, 1].AddParagraph();
- para = table[2, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("PROVIDER");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[2, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("BUYER");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("NAME: " + contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address: " + contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- //para = table[3, 0].AddParagraph();
- //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- //textRange = para.AppendText("Tax code: " + "0108453894");
- //textRange.CharacterFormat.FontName = "Times New Roman";
- //textRange.CharacterFormat.FontSize = 11;
- //textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("NAME: " + contract.telco);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address: " + contract.addressTelco);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- //para = table[3, 1].AddParagraph();
- //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- //textRange = para.AppendText("Tax code: " + "1150150");
- //textRange.CharacterFormat.FontName = "Times New Roman";
- //textRange.CharacterFormat.FontSize = 11;
- //textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para = table[4, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("DEFINITION OF PAYMENT");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- IWTable table2 = table[4, 1].AddTable();
- rowNum = 1; columnNum = 3;
- table2.ResetCells(rowNum, columnNum);
- table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table2.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table2.Rows[j].Cells[i];
- if (i == 1)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- else
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- }
- }
- IWParagraph para2 = table2[0, 0].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("QUANTITY");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- para2 = table2[0, 1].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("UNIT PRICE (USD)");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- para2 = table2[0, 2].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("TOTAL (USD)");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- //
- para = table[5, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.service + " SHARING REVENUE OF " + convertTime.AddMonths(-1).ToString("MMMM yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[5, 0].AddParagraph();
- table2 = table[5, 1].AddTable();
- rowNum = 1; columnNum = 3;
- table2.ResetCells(rowNum, columnNum);
- table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table2.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table2.Rows[j].Cells[i];
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- if (i == 1)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- else
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- }
- }
- para2 = table2[0, 0].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("1");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para2 = table2[0, 0].AddParagraph();
- para2 = table2[0, 0].AddParagraph();
- para2 = table2[0, 1].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para2 = table2[0, 1].AddParagraph();
- para2 = table2[0, 1].AddParagraph();
- para2 = table2[0, 2].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para2 = table2[0, 2].AddParagraph();
- para2 = table2[0, 2].AddParagraph();
- para = table[6, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("TOTAL");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("By word:");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;
- textRange = para.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(ConvertAmount(double.Parse(contract.money)) + " Dollars.");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 0].AddParagraph();
- para = table[6, 1].AddParagraph();
- // content
- //Appends paragraph.
- IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Please remit payment to:") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 5; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- if (i == 0)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- else if (i == 1)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- }
- }
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Name of Beneficiary");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.beneficiary);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[2, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Name of Beneficiary’s bank");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[2, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.bank);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Account number");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.account);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[4, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("SWIFT Code");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[4, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.swiftCode);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 1; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- table.TableFormat.Borders.Color = Color.White;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.6 : tableWidth * 0.4);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
- }
- }
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("SIGNATURE");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- //Saves the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- document.Save(stream, FormatType.Docx);
- stream.Position = 0;
- bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- if (!exists)
- System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- FileStream outputStream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- document.Save(outputStream, FormatType.Docx);
- document.Close();
- outputStream.Flush();
- outputStream.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("Exp: " + ex);
- return false;
- }
- }
- public static bool PaymentNatcomAllDumpt(Contract contract)
- {
- try
- {
- string[] validformats = new[] { "dd/MM/yyyy", "dd-MMM-yyyy" };
- DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
- CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- // Creating a new document.
- WordDocument document = new WordDocument();
- // Setting document page margins.
- MarginsF pagemargins = new MarginsF();
- pagemargins.Bottom = 20;
- pagemargins.Top = 20;
- pagemargins.Left = 75;
- pagemargins.Right = 75;
- // Assigning document page margins to the current section.
- IWSection section = document.AddSection();
- section.PageSetup.Margins = pagemargins;
- section.AddParagraph();
- IWTable table = section.AddTable();
- int rowNum = 1, columnNum = 2;
- RowFormat format = new RowFormat();
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? table.Width * 0.5 : table.Width * 0.5);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- }
- }
- IWParagraph para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- IWTextRange textRange = para.AppendText(contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- //textRange = table[0, 0].AddParagraph().AppendText("");
- String d1 = "NO: " + "07/2019" + "/" + "MTV " + contract.syntaxConpany + "NV - " + contract.syntaxTelco + " - " + contract.service;
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText(d1);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("SOCIALIST REPUBLIC OF VIETNAM");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("Freedom - Equality - Fraternity");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- textRange = table[0, 1].AddParagraph().AppendText("");
- String d2 = "Hanoi, " + convertTime.ToString("dd-MMMM, yyyy");
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText(d2);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- // content
- //Appends paragraph.
- IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = paragraph.AppendText("PAYMENT REQUEST") as WTextRange;
- textRange.CharacterFormat.FontSize = 15;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = paragraph.AppendText("To " + contract.telco) as WTextRange;
- textRange.CharacterFormat.FontSize = 15;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "According to the contract No ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(contract.contractCode) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange = paragraph.AppendText(" service provision contract and if there is content of contract") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange = paragraph.AppendText(" regarding to providing service on " + contract.syntaxTelco + " Mobile network between " + contract.syntaxTelco + " and ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(contract.company + ".") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "According to COMMERCIAL INVOICE No: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- String d3 = convertTime.ToString("ddMMyyyy") + "-" + contract.id + " " + contract.service;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(d3) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "According to Form of Yield Confirmation – Income of ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(contract.service) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" Service between " + contract.telco + " and ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(contract.company) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" for month ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(convertTime.AddMonths(-1).ToString("MMMM yyyy") + ".") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + contract.syntaxTelco + " must make payment to " + contract.company + " for " + convertTime.AddMonths(-1).ToString("MMMM yyyy") + " : ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(contract.company) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" for ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(convertTime.ToString("MMMM yyyy") + " : ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "$ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "Total : $ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- //paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("In words : " + ConvertAmount(double.Parse(contract.money)) + " dollars./.") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- //paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "Thus, you are requested to transfer the payment above and fax us the T/T remittance once available ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- //paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "Payment method and currency : Telegraphic in USD") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 5; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- float tableWidth = table.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- }
- }
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Beneficiary");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Account No.");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[2, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Bank");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[4, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Swift Code");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- /////--------------
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.beneficiary);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.account);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[2, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.bank);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[4, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.swiftCode);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Best Regards, ") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- table = section.AddTable();
- rowNum = 1; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- table.TableFormat.Borders.Color = Color.White;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.2 : tableWidth * 0.8);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
- }
- }
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText(contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("Director");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- //Saves the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- document.Save(stream, FormatType.Docx);
- stream.Position = 0;
- bool exists = Directory.Exists("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
- if (!exists)
- Directory.CreateDirectory("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
- FileStream outputStream = new FileStream("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_payment_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- document.Save(outputStream, FormatType.Docx);
- document.Close();
- outputStream.Flush();
- outputStream.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("Exp: " + ex);
- }
- return false;
- }
- public static bool PaymentDumpt(Contract contract)
- {
- try
- {
- string[] validformats = new[] { "dd/MM/yyyy", "dd-MMM-yyyy" };
- DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
- CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- int coChu = 12;
- // Creating a new document.
- WordDocument document = new WordDocument();
- // Setting document page margins.
- MarginsF pagemargins = new MarginsF();
- pagemargins.Bottom = 20;
- pagemargins.Top = 20;
- pagemargins.Left = 75;
- pagemargins.Right = 75;
- // Assigning document page margins to the current section.
- IWSection section = document.AddSection();
- section.PageSetup.Margins = pagemargins;
- section.AddParagraph();
- IWTable table = section.AddTable();
- int rowNum = 1, columnNum = 2;
- RowFormat format = new RowFormat();
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? table.Width * 0.5 : table.Width * 0.5);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- }
- }
- IWParagraph para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- IWTextRange textRange = para.AppendText(contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = true;
- //textRange = table[0, 0].AddParagraph().AppendText("");
- String d1 = "NO: " + convertTime.ToString(contract.syntaxConpany == "GTS" ? "ddMM/yyyy" : "MM/yyyy") + "/" + contract.syntaxConpany + " - " + contract.syntaxTelco + " - " + contract.service;
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText(d1);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = false;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("SOCIALIST REPUBLIC OF VIETNAM");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("Freedom - Equality - Fraternity");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = true;
- textRange = table[0, 1].AddParagraph().AppendText("");
- String d2 = "Hanoi, " + convertTime.ToString("dd-MMMM, yyyy");
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText(d2);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = false;
- // content
- //Appends paragraph.
- IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = paragraph.AppendText("PAYMENT REQUEST") as WTextRange;
- textRange.CharacterFormat.FontSize = 15;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("To: ") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(contract.telco) as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Taxtcode: 1150150") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("According to the contract " + contract.contractCode) as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(" service provision contract and content of contract") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(" regarding to providing " + contract.service + " service on " + contract.syntaxTelco + " Mobile network between " + contract.syntaxTelco + " and " + contract.company + ".") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- String d3 = convertTime.ToString(contract.syntaxConpany == "ITL" || contract.syntaxConpany == "INTERLAND" ? "yyyyMMdd" : "ddMMyyyy") + "-" + contract.id;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "According to COMMERCIAL INVOICE No: " + d3) as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "According to Form of Yield Confirmation – Income of " + contract.service + " Service between " + contract.syntaxTelco + " and " + contract.company + " for month " + convertTime.AddMonths(-1).ToString("MMMM yyyy") + ".") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + contract.syntaxTelco + " must make payment to " + contract.company + " for " + convertTime.AddMonths(-1).ToString("MMMM yyyy") + " : ") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("$ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "Total : $ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("In words : ") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- if (contract.contractCode == "VIETTECH")
- {
- textRange = paragraph.AppendText(ConvertAmount(double.Parse(contract.money)) + " United States Dollars.") as WTextRange;
- }
- else if (contract.contractCode == "ITL" || contract.contractCode == "INTERLAND")
- {
- textRange = paragraph.AppendText(ConvertAmount(double.Parse(contract.money)) + " USD.") as WTextRange;
- }
- else
- {
- textRange = paragraph.AppendText(ConvertAmount(double.Parse(contract.money)) + " dollars./.") as WTextRange;
- }
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange.CharacterFormat.Italic = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "Thus, you are requested to transfer the payment above and fax us the T/T remittance once available ") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(" " + "Payment method and currency : Telegraphic in USD") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 5; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- float tableWidth = table.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- }
- }
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.syntaxConpany == "GTS" ? "Name of Beneficiary" : "Beneficiary");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
- para = table[2, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.syntaxConpany == "GTS" ? "Bank account:" : "Account No.");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.syntaxConpany == "GTS" ? "Bank Name" : "Bank");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
- para = table[4, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Swift Code:");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
- /////--------------
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.beneficiary);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = false;
- para = table[2, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.account);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.bank);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = false;
- para = table[4, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.swiftCode);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Best Regards, ") as WTextRange;
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- table = section.AddTable();
- rowNum = 1; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- table.TableFormat.Borders.Color = Color.White;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.2 : tableWidth * 0.8);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
- }
- }
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText(contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("Director");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = coChu;
- textRange.CharacterFormat.Bold = true;
- //Saves the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- document.Save(stream, FormatType.Docx);
- stream.Position = 0;
- bool exists = Directory.Exists("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
- if (!exists)
- Directory.CreateDirectory("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
- FileStream outputStream = new FileStream("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_payment_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- document.Save(outputStream, FormatType.Docx);
- document.Close();
- outputStream.Flush();
- outputStream.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("Exp: " + ex);
- }
- return false;
- }
- public static bool InvoiceGTSDumpt(Contract contract)
- {
- try
- {
- string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
- "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
- DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
- CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- // Creating a new document.
- WordDocument document = new WordDocument();
- // Setting document page margins.
- MarginsF pagemargins = new MarginsF();
- pagemargins.Bottom = 20;
- pagemargins.Top = 20;
- pagemargins.Left = 75;
- pagemargins.Right = 75;
- // Assigning document page margins to the current section.
- IWSection section = document.AddSection();
- section.PageSetup.Margins = pagemargins;
- section.AddParagraph();
- IWTable table = section.AddTable();
- int rowNum = 1, columnNum = 2;
- RowFormat format = new RowFormat();
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? table.Width * 0.65 : table.Width * 0.35);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
- }
- }
- IWParagraph para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- IWTextRange textRange = para.AppendText(contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Add: " + contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = false;
- para = table[0, 0].AddParagraph();
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Registration Number: ");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = true;
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("0108079693");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = false;
- // Gets the image stream.
- para = table[0, 1].AddParagraph();
- FileStream imageStream = new FileStream("./resources/gts.jpg", FileMode.Open, FileAccess.Read);
- IWPicture picture = para.AppendPicture(imageStream);
- picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
- picture.VerticalOrigin = VerticalOrigin.Margin;
- //picture.VerticalPosition = -45;
- //picture.HorizontalOrigin = HorizontalOrigin.Column;
- //picture.HorizontalPosition = 263.5f;
- //picture.WidthScale = 20;
- //picture.HeightScale = 15;
- // content
- //Appends paragraph.
- IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = paragraph.AppendText("INVOICE") as WTextRange;
- textRange.CharacterFormat.FontSize = 25;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange.CharacterFormat.TextColor = Color.Orange;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 1; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- float tableWidth = table.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.5 : tableWidth * 0.5);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot;
- }
- }
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("No: ");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 15;
- textRange.CharacterFormat.Bold = true;
- textRange = para.AppendText(convertTime.ToString("ddMMyyyy") + "-" + contract.id);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 13;
- textRange.CharacterFormat.Bold = false;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Date: ");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 15;
- textRange.CharacterFormat.Bold = true;
- textRange = para.AppendText(convertTime.ToString("dd/MM/yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 13;
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText(contract.telco) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Address: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange = paragraph.AppendText("CBD 4 Timor Plaza, Comoro, Dili, Timor Leste") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Tax Registration No : ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange = paragraph.AppendText("1150150") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Attention: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange = paragraph.AppendText("Mr. Tran Van Bang") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Contract: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- textRange = paragraph.AppendText(contract.contractCode) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 2; columnNum = 3;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.1 : i == 1 ? tableWidth * 0.6 : tableWidth * 0.3);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot;
- }
- }
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("No");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 14;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("Description");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 14;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 2].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("Amount");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 14;
- textRange.CharacterFormat.Bold = true;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("1");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.service + " service sharing revenue of " + convertTime.AddMonths(-1).ToString("MMMM yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 14;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 2].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("USD " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 14;
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("In writing: " + ConvertAmount(double.Parse(contract.money)) + " dollars./.") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Following is the Payment reference:") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("- Name of Bank: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(contract.bank) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("- Address: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(contract.address) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("- Swift Code: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(contract.swiftCode) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("- Account No: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(contract.account) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("- Account holdere: ") as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- textRange = paragraph.AppendText(contract.beneficiary) as WTextRange;
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = false;
- table = section.AddTable();
- rowNum = 1; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- table.TableFormat.Borders.Color = Color.White;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
- }
- }
- para = table[0, 1].AddParagraph();
- para = table[0, 1].AddParagraph();
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("DIRECTOR");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 17;
- textRange.CharacterFormat.Bold = true;
- //Saves the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- document.Save(stream, FormatType.Docx);
- stream.Position = 0;
- bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- if (!exists)
- System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- FileStream outputStream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- document.Save(outputStream, FormatType.Docx);
- document.Close();
- outputStream.Flush();
- outputStream.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("Exp: " + ex);
- return false;
- }
- }
- public static bool InvoiceVTECHDumpt(Contract contract)
- {
- try
- {
- string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
- "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
- DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
- CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- // Creating a new document.
- WordDocument document = new WordDocument();
- // Setting document page margins.
- MarginsF pagemargins = new MarginsF();
- pagemargins.Bottom = 20;
- pagemargins.Top = 20;
- pagemargins.Left = 75;
- pagemargins.Right = 75;
- // Assigning document page margins to the current section.
- IWSection section = document.AddSection();
- section.PageSetup.Margins = pagemargins;
- section.AddParagraph();
- IWTable table = section.AddTable();
- int rowNum = 7, columnNum = 2;
- RowFormat format = new RowFormat();
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- float tableWidth = table.Width;
- //table.TableFormat.BackColor = Color.FromArgb(192, 192, 192);
- table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[0].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[2].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[2].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[4].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- table.Rows[4].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.5 : tableWidth * 0.5);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- if (i == 0)
- {
- if (j == 6)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- else if (j == 1 || j == 2 || j == 5 || j == 4)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- else
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- }
- else if (i == 1)
- {
- if (j == 6)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- else if (j == 1 || j == 2 || j == 5 || j == 4)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
- }
- else
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- }
- }
- }
- }
- table.ApplyHorizontalMerge(0, 0, 1);
- IWParagraph para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- IWTextRange textRange = para.AppendText("COMMERCIAL INVOICE");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 16;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("No: " + convertTime.ToString("ddMMyyyy") + "-" + contract.id);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 13;
- textRange.CharacterFormat.Bold = true;
- para = table[0, 0].AddParagraph();
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("DATE OF EXPORT");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(convertTime.ToString("dd/MM/yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 0].AddParagraph();
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("CONTRACT");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- //String d1 = (int.Parse(contract.id) < 10 ? "0" + contract.id : contract.id) + "/VTL-" + contract.syntaxConpany + "/VAS/" + convertTime.ToString("yyyy");
- String d1 = contract.contractCode;
- textRange = para.AppendText(d1);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 1].AddParagraph();
- para = table[2, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("PROVIDER");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[2, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("BUYER");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("NAME: " + contract.company);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address: " + contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Tax code: " + "0108453894");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("NAME: " + contract.telco);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address: " + contract.addressTelco + ".");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Tax code: " + "1150150");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para = table[4, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("DEFINITION OF PAYMENT");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- IWTable table2 = table[4, 1].AddTable();
- rowNum = 1; columnNum = 3;
- table2.ResetCells(rowNum, columnNum);
- table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table2.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table2.Rows[j].Cells[i];
- if (i == 1)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- else
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- }
- }
- IWParagraph para2 = table2[0, 0].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("QUANTITY");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- para2 = table2[0, 1].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("UNIT PRICE (USD)");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- para2 = table2[0, 2].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("TOTAL (USD)");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 10;
- textRange.CharacterFormat.Bold = true;
- //
- para = table[5, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.service + " service sharing revenue of " + convertTime.AddMonths(-1).ToString("MMMM yyyy"));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[5, 0].AddParagraph();
- table2 = table[5, 1].AddTable();
- rowNum = 1; columnNum = 3;
- table2.ResetCells(rowNum, columnNum);
- table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table2.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table2.Rows[j].Cells[i];
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- if (i == 1)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- }
- else
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- }
- }
- para2 = table2[0, 0].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText("1");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para2 = table2[0, 0].AddParagraph();
- para2 = table2[0, 0].AddParagraph();
- para2 = table2[0, 1].AddParagraph();
- para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para2 = table2[0, 1].AddParagraph();
- para2 = table2[0, 1].AddParagraph();
- para2 = table2[0, 2].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para2 = table2[0, 2].AddParagraph();
- para2 = table2[0, 2].AddParagraph();
- para = table[6, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("TOTAL");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 12;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("By word:");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;
- textRange = para.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- para = table[6, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(ConvertAmount(double.Parse(contract.money)) + " Dollars.");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- // content
- //Appends paragraph.
- IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph = section.AddParagraph();
- paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = paragraph.AppendText("Please remit payment to:") as WTextRange;
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.Bold = true;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 5; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- if (i == 0)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- else if (i == 1)
- {
- cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
- cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
- cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
- }
- }
- }
- para = table[0, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Name of Beneficiary");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.beneficiary);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Address");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[1, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.address);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[2, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Name of Beneficiary’s bank");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[2, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.bank);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("Account number");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[3, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.account);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[4, 0].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText("SWIFT Code");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- para = table[4, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
- textRange = para.AppendText(contract.swiftCode);
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = false;
- paragraph = section.AddParagraph();
- table = section.AddTable();
- rowNum = 1; columnNum = 2;
- table.ResetCells(rowNum, columnNum);
- table.TableFormat.HorizontalAlignment = RowAlignment.Center;
- tableWidth = table.Width;
- table.TableFormat.Borders.Color = Color.White;
- for (int i = 0; i < columnNum; i++)
- {
- for (int j = 0; j < rowNum; j++)
- {
- WTableCell cell = table.Rows[j].Cells[i];
- cell.Width = (float)(i == 0 ? tableWidth * 0.6 : tableWidth * 0.4);
- cell.CellFormat.Paddings.Top = 5;
- cell.CellFormat.Paddings.Bottom = 5;
- cell.CellFormat.Paddings.Left = 5;
- cell.CellFormat.Paddings.Right = 5;
- cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
- }
- }
- para = table[0, 1].AddParagraph();
- para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
- textRange = para.AppendText("SIGNATURE");
- textRange.CharacterFormat.FontName = "Times New Roman";
- textRange.CharacterFormat.FontSize = 11;
- textRange.CharacterFormat.Bold = true;
- //Saves the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- document.Save(stream, FormatType.Docx);
- stream.Position = 0;
- bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- if (!exists)
- System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- FileStream outputStream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- document.Save(outputStream, FormatType.Docx);
- document.Close();
- outputStream.Flush();
- outputStream.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("Exp: " + ex);
- return false;
- }
- }
- public static bool InvoiceITLDumpt(Contract contract)
- {
- try
- {
- string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
- "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
- DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
- CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- ExcelEngine excelEngine = new ExcelEngine();
- int rowCount = 1;
- IApplication application = excelEngine.Excel;
- application.DefaultVersion = ExcelVersion.Excel2013;
- IWorkbook workbook = application.Workbooks.Create(1);
- IWorksheet worksheet = workbook.Worksheets[0];
- List<RowAttributed> rowAttributedList = new List<RowAttributed>();
- worksheet.Range["A1"].ColumnWidth = 3;
- worksheet.Range["B1"].ColumnWidth = 50;
- worksheet.Range["C1"].ColumnWidth = 8;
- worksheet.Range["D1"].ColumnWidth = 14;
- worksheet.Range["E1"].ColumnWidth = 18;
- worksheet.Range["F1"].ColumnWidth = 30;
- //Defining body style
- Syncfusion.XlsIO.IStyle bodyStyle = workbook.Styles.Add("BodyStyle");
- bodyStyle.BeginUpdate();
- bodyStyle.Color = Color.FromArgb(255, 255, 255);
- bodyStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.None;
- bodyStyle.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.None;
- bodyStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.None;
- bodyStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.None;
- bodyStyle.EndUpdate();
- worksheet.Range["A1:F39"].CellStyle = bodyStyle;
- // style
- Syncfusion.XlsIO.IStyle cellStyleTableCenterBold = workbook.Styles.Add("table-center-bold");
- cellStyleTableCenterBold.Font.Size = 12;
- cellStyleTableCenterBold.Font.Bold = true;
- cellStyleTableCenterBold.Font.FontName = "Roboto";
- cellStyleTableCenterBold.HorizontalAlignment = ExcelHAlign.HAlignCenter;
- cellStyleTableCenterBold.VerticalAlignment = ExcelVAlign.VAlignCenter;
- cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
- cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
- cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thin;
- cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thin;
- Syncfusion.XlsIO.IStyle cellStyleTableCenterNormal = workbook.Styles.Add("table-center-normal");
- cellStyleTableCenterNormal.Font.Size = 12;
- cellStyleTableCenterNormal.Font.Bold = false;
- cellStyleTableCenterNormal.Font.FontName = "Roboto";
- cellStyleTableCenterNormal.HorizontalAlignment = ExcelHAlign.HAlignCenter;
- cellStyleTableCenterNormal.VerticalAlignment = ExcelVAlign.VAlignCenter;
- cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
- cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
- cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thin;
- cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thin;
- Syncfusion.XlsIO.IStyle cellStyleTextBold = workbook.Styles.Add("text-bold");
- cellStyleTextBold.Font.Size = 12;
- cellStyleTextBold.Font.Bold = true;
- cellStyleTextBold.Font.FontName = "Roboto";
- Syncfusion.XlsIO.IStyle cellStyleTextBoldCenter = workbook.Styles.Add("text-bold-center");
- cellStyleTextBoldCenter.Font.Size = 12;
- cellStyleTextBoldCenter.Font.Bold = true;
- cellStyleTextBoldCenter.HorizontalAlignment = ExcelHAlign.HAlignCenter;
- cellStyleTextBoldCenter.Font.FontName = "Roboto";
- Syncfusion.XlsIO.IStyle cellStyleTextNormal = workbook.Styles.Add("text-normal");
- cellStyleTextNormal.Font.Size = 12;
- cellStyleTextNormal.Font.Bold = false;
- cellStyleTextNormal.Font.FontName = "Roboto";
- Syncfusion.XlsIO.IStyle cellStyleTextNormalCenter = workbook.Styles.Add("text-normal-center");
- cellStyleTextNormalCenter.Font.Size = 12;
- cellStyleTextNormalCenter.Font.Bold = false;
- cellStyleTextNormalCenter.HorizontalAlignment = ExcelHAlign.HAlignCenter;
- cellStyleTextNormalCenter.Font.FontName = "Roboto";
- worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
- Syncfusion.XlsIO.IStyle rowStyle = workbook.Styles.Add("style1");
- rowStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.None;
- rowStyle.Color = Color.FromArgb(255, 174, 33);
- worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = rowStyle;
- rowCount++;
- worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
- rowStyle = workbook.Styles.Add("style2");
- rowStyle.Color = Color.FromArgb(255, 0, 0);
- worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = rowStyle;
- worksheet.Range[GetExcelColumnName(1) + 39.ToString() + ":" + GetExcelColumnName(6) + 39.ToString()].CellStyle = rowStyle;
- rowCount++;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "INVOICE";
- Syncfusion.XlsIO.IStyle cellStyle = workbook.Styles.Add("style3");
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].RowHeight = 120;
- cellStyle.Font.Size = 24;
- cellStyle.Font.Bold = true;
- cellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyle;
- //Adding a picture
- FileStream imageStream = new FileStream("./resources/ITL.jpg", FileMode.Open, FileAccess.Read);
- IPictureShape shape = worksheet.Pictures.AddPicture(6, 3, imageStream);
- //Positioning a Picture
- shape.Top = 60;
- shape.Left = 700;
- //Re-sizing a Picture
- shape.Height = 160;
- shape.Width = 180;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(5) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.company;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextBold;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = convertTime.ToString("dd/MM/yyyy");
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(5) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.address;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].RowHeight = 40;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].WrapText = true;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = "INVOICE No." + convertTime.ToString("yyyyMMdd") + "-" + contract.id;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(5) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Tax Code: 0107836502";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Email: vninterland@gmail.com";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- rowCount += 3;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "BILL TO";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextBold;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].ColorRGB = Color.FromArgb(215, 215, 215);
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
- rowCount += 3;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.telco;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextBold;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.addressTelco;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Tel: +670 76900005";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Tax code: 1150150";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- rowCount ++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.contractCode;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
- rowCount += 2;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "DESCRIPTION";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle.Font.Size = 11;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = "QTY";
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle.Font.Size = 11;
- worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].Text = "UNIT PRICE (USD)";
- worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
- worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].CellStyle.Font.Size = 11;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = "TOTAL (USD)";
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle.Font.Size = 11;
- rowCount++;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(2) + (rowCount + 1).ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.service + " service sharing revenue of " + convertTime.AddMonths(-1).ToString("MMMM yyyy");
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].CellStyle = cellStyleTableCenterNormal;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(2) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterNormal;
- worksheet.Range[GetExcelColumnName(3) + rowCount.ToString() + ":" + GetExcelColumnName(3) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterNormal;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = "1";
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(4) + (rowCount + 1).ToString()].Merge();
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle = cellStyleTableCenterNormal;
- worksheet.Range[GetExcelColumnName(5) + rowCount.ToString() + ":" + GetExcelColumnName(5) + (rowCount + 1).ToString()].Merge();
- worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].Text = int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture);
- worksheet.Range[GetExcelColumnName(5) + rowCount.ToString() + ":" + GetExcelColumnName(5) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterNormal;
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString() + ":" + GetExcelColumnName(6) + (rowCount + 1).ToString()].Merge();
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture);
- worksheet.Range[GetExcelColumnName(6) + rowCount.ToString() + ":" + GetExcelColumnName(6) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterBold;
- rowCount += 2;
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "By word: " + ConvertAmount(double.Parse(contract.money)) + " USD.";
- worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTableCenterNormal;
- rowCount += 2;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = contract.company;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle.Font.Size = 11;
- rowCount++;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = "DIRECTOR";
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
- worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle.Font.Size = 11;
- rowCount++;
- //Saving the workbook as stream
- bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- if (!exists)
- System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
- FileStream stream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".xlsx", FileMode.Create, FileAccess.ReadWrite);
- workbook.SaveAs(stream);
- stream.Dispose();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("Exp: " + ex);
- return false;
- }
- }
- private static String[] units = { "Zero", "One", "Two", "Three",
- "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
- "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
- "Seventeen", "Eighteen", "Nineteen" };
- private static String[] unitsNormal = { "zero", "one", "two", "three",
- "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
- "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
- "seventeen", "eighteen", "nineteen" };
- private static String[] tens = { "", "", "Twenty", "Thirty", "Forty",
- "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
- private static String[] tensNormal = { "", "", "twenty", "thirty", "forty",
- "fifty", "sixty", "seventy", "eighty", "ninety" };
- public static String ConvertAmount(double amount)
- {
- try
- {
- Int64 amount_int = (Int64)amount;
- Int64 amount_dec = (Int64)Math.Round((amount - (double)(amount_int)) * 100);
- if (amount_dec == 0)
- {
- return FirstLetterToUpperCase(ConvertEnglish(amount_int));
- }
- else
- {
- return FirstLetterToUpperCase(ConvertEnglish(amount_int)) + " Point " + ConvertEnglish(amount_dec);
- }
- }
- catch (Exception e)
- {
- // TODO: handle exception
- }
- return "";
- }
- public static String ConvertEnglish(Int64 i)
- {
- if (i < 20)
- {
- return unitsNormal[i];
- }
- if (i < 100)
- {
- return tensNormal[i / 10] + ((i % 10 > 0) ? " " + ConvertEnglish(i % 10) : "");
- }
- if (i < 1000)
- {
- return unitsNormal[i / 100] + " hundred"
- + ((i % 100 > 0) ? " and " + ConvertEnglish(i % 100) : "");
- }
- if (i < 100000)
- {
- return ConvertEnglish(i / 1000) + " thousand "
- + ((i % 1000 > 0) ? " " + ConvertEnglish(i % 1000) : "");
- }
- if (i < 10000000)
- {
- return ConvertEnglish(i / 100000) + " lakh "
- + ((i % 100000 > 0) ? " " + ConvertEnglish(i % 100000) : "");
- }
- if (i < 1000000000)
- {
- return ConvertEnglish(i / 10000000) + " crore "
- + ((i % 10000000 > 0) ? " " + ConvertEnglish(i % 10000000) : "");
- }
- return ConvertEnglish(i / 1000000000) + " arab "
- + ((i % 1000000000 > 0) ? " " + ConvertEnglish(i % 1000000000) : "");
- }
- public static List<String> StringSeprate(String input, int numCharacter)
- {
- string[] words = input.Split(' ');
- int counter = 0;
- int countWord = 0;
- String result = "";
- String result2 = "";
- for (int i = 0; i < words.Length; i++)
- {
- int nextCounter = counter + words[i].Length;
- if (nextCounter < numCharacter)
- {
- countWord++;
- if (counter == 0)
- result += words[i];
- else
- result += (" " + words[i]);
- }
- counter = nextCounter;
- }
- for (int i = countWord; i < words.Length; i++)
- {
- if (i == countWord)
- result2 += words[i];
- else
- result2 += (" " + words[i]);
- }
- List<String> res = new List<string>();
- res.Add(result);
- res.Add(result2);
- return res;
- }
- public static string FirstLetterToUpperCase(string s)
- {
- if (string.IsNullOrEmpty(s))
- throw new ArgumentException("There is no first letter");
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
- public static void SaveDocFile(String inputFileName)
- {
- //Open an existing WordDocument
- FileStream inputStream = new FileStream(inputFileName, FileMode.Open);
- WordDocument document = new WordDocument(inputStream, FormatType.Docx);
- //To-Do some manipulation
- //To-Do some manipulation
- //Saving the Word document
- FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- document.Save(outputStream, FormatType.Docx);
- document.Close();
- outputStream.Flush();
- outputStream.Dispose();
- }
- private static void IterateTextBody(WTextBody textBody)
- {
- //Iterates through each of the child items of WTextBody
- for (int i = 0; i < textBody.ChildEntities.Count; i++)
- {
- //IEntity is the basic unit in DocIO DOM.
- //Accesses the body items (should be either paragraph, table or block content control) as IEntity
- IEntity bodyItemEntity = textBody.ChildEntities[i];
- //A Text body has 3 types of elements - Paragraph, Table and Block Content Control
- //Decides the element type by using EntityType
- switch (bodyItemEntity.EntityType)
- {
- case EntityType.Paragraph:
- WParagraph paragraph = bodyItemEntity as WParagraph;
- //Checks for particular style name and removes the paragraph from DOM
- if (paragraph.StyleName == "MyStyle")
- {
- int index = textBody.ChildEntities.IndexOf(paragraph);
- textBody.ChildEntities.RemoveAt(index);
- }
- break;
- case EntityType.Table:
- //Table is a collection of rows and cells
- //Iterates through table's DOM
- IterateTable(bodyItemEntity as WTable);
- break;
- case EntityType.BlockContentControl:
- BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
- //Iterates to the body items of Block Content Control.
- IterateTextBody(blockContentControl.TextBody);
- break;
- }
- }
- }
- public static string GetExcelColumnName(int columnNumber)
- {
- int dividend = columnNumber;
- string columnName = String.Empty;
- int modulo;
- while (dividend > 0)
- {
- modulo = (dividend - 1) % 26;
- columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
- dividend = (int)((dividend - modulo) / 26);
- }
- return columnName;
- }
- private static void IterateTable(WTable table)
- {
- //Iterates the row collection in a table
- foreach (WTableRow row in table.Rows)
- {
- //Iterates the cell collection in a table row
- foreach (WTableCell cell in row.Cells)
- {
- //Table cell is derived from (also a) TextBody
- //Reusing the code meant for iterating TextBody
- IterateTextBody(cell);
- }
- }
- }
- public static bool CheckFile(String path)
- {
- return File.Exists(path);
- }
- public static void DeleteFile(String path)
- {
- File.Delete(path);
- }
- public static Byte[] GetFileByte(String path)
- {
- var dataBytes = File.ReadAllBytes(path);
- return dataBytes;
- }
- public static Dictionary<String, String> GetAttribute(String data)
- {
- Dictionary<String, String> attributes = new Dictionary<String, String>();
- string[] seprateSpace = data.Split(" ");
- for (int i = 0; i < seprateSpace.Length; i++)
- {
- string[] seprateEqual = seprateSpace[i].Split("=\"");
- if (seprateEqual.Length >= 2)
- {
- if (seprateEqual[0] == "\"__VIEWSTATEGENERATOR\"")
- {
- attributes.Add(seprateEqual[0], seprateEqual[1].Remove(seprateEqual[1].Length - 1, 1));
- }
- else
- {
- Regex regex = new Regex("value=(['\"])(?:\\/.+?)\\1", RegexOptions.IgnoreCase);
- Match match;
- string value = seprateEqual[1];
- for (match = regex.Match(seprateSpace[i]); match.Success; match = match.NextMatch())
- {
- string d = match.Groups[0].Value.Substring(7);
- value = d.Remove(d.Length - 1, 1);
- }
- attributes.Add(seprateEqual[0], value);
- }
- }
- }
- return attributes;
- }
- public static List<KeyValuePair<string, string>> ParseDataRequest(String responseText)
- {
- List<KeyValuePair<string, string>> data;
- data = new List<KeyValuePair<string, string>>();
- Regex regex = new Regex("<input.*?(?:name=\"*\".*?value=\"([^\"]+)| value =\"([^\"]+).*? name =\"*\")\"[^>]*>", RegexOptions.IgnoreCase);
- Match match;
- for (match = regex.Match(responseText); match.Success; match = match.NextMatch())
- {
- Dictionary<String, String> attrs = UtilsController.GetAttribute(match.Groups[0].Value);
- String key = "";
- String value = "";
- foreach (KeyValuePair<string, string> item in attrs)
- {
- if (item.Key == "name")
- {
- key = item.Value;
- }
- if (item.Key == "value")
- {
- value = item.Value;
- }
- }
- if (!key.Contains("cmdTraCuu") && !key.Contains("__EVENTTARGET") && !key.Contains("__EVENTARGUMENT"))
- {
- string resultKey = Regex.Replace(key, @"[^\w\d]", "");
- data.Add(new KeyValuePair<string, string>(resultKey, value));
- }
- }
- return data;
- }
- }
- }
|