Advertisement
Guest User

XorpiZ

a guest
May 5th, 2010
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. using System.Web;
  11. using System.IO;
  12. using System.Deployment;
  13. using System.Deployment.Application;
  14.  
  15. namespace WindowsFormsApplication1
  16. {
  17.     public partial class Form1 : Form
  18.     {
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void button1_Click(object sender, EventArgs e)
  25.         {
  26.             SqlConnection myConnection = new SqlConnection("user id=user;" +
  27.                            "password=pw;server=server;" +
  28.                            "Trusted_Connection=no;" +
  29.                            "database=db; " +
  30.                            "connection timeout=30");
  31.  
  32.             try
  33.             {
  34.                 myConnection.Open();
  35.             }
  36.             catch (Exception f)
  37.             {
  38.                 MessageBox.Show(f.ToString());
  39.             }
  40.            
  41.             bool fakturering = false;
  42.             bool levering = false;
  43.             string SQLData = "";
  44.             string firma = null;
  45.             string filnavn = null;
  46.  
  47.             string dato = kalender.SelectionStart.ToString("s");
  48.             dato = dato.Remove(10, 9);
  49.  
  50.             if (faktureringsButton.Checked)
  51.             {
  52.                 fakturering = true;
  53.             }
  54.  
  55.             else if (leveringsButton.Checked)
  56.             {
  57.                 levering = true;
  58.             }
  59.  
  60.             if (firmaButton.Checked)
  61.             {
  62.                 if (levering)
  63.                 {
  64.                     SQLData = "SELECT [Customer No_], [Firma A_S$Ship-to Address].Name, [Firma A_S$Ship-to Address].[Name 2], [Firma A_S$Ship-to Address].Address, [Firma A_S$Ship-to Address].[Address 2], [Firma A_S$Ship-to Address].[Post Code], [Firma A_S$Ship-to Address].City, [Firma A_S$Ship-to Address].[Country_Region Code] " +
  65.                         "FROM [Firma A_S$Ship-to Address] " +
  66.                         "LEFT JOIN [Firma A_S$Customer] " +
  67.                         "ON [Firma A_S$Ship-to Address].[Customer No_] = [Firma A_S$Customer].[No_] " +
  68.                         "WHERE [Firma A_S$Ship-to Address].[Last Date Modified] >= '" + dato + "' " +
  69.                         "OR [Firma A_S$Customer].[Last Date Modified] >= '" + dato + "'";
  70.  
  71.                 }
  72.                 else if (fakturering)
  73.                 {
  74.                     SQLData = "SELECT No_, Name, [Name 2], Address, [Address 2], [Post Code], City, [Country_Region Code] " +
  75.                               "FROM [Firma A_S$Customer] " +
  76.                               "WHERE [Firma A_S$Customer].[Last Date Modified]>='" + dato + "'";
  77.                 }
  78.                 firma = "firma";
  79.             }
  80.             else if (firma3Button.Checked)
  81.             {
  82.                 if (levering)
  83.                 {
  84.                     SQLData = "SELECT [Customer No_], [Firma3 A_S$Ship-to address].Name, [Firma3 A_S$Ship-to address].[Name 2], [Firma3 A_S$Ship-to address].Address, [Firma3 A_S$Ship-to address].[Address 2], [Firma3 A_S$Ship-to address].[Post Code], [Firma3 A_S$Ship-to address].City, [Firma3 A_S$Ship-to address].[Country_Region Code] " +
  85.                         "FROM [Firma3 A_S$Ship-to Address] " +
  86.                         "LEFT JOIN [Firma3 A_S$Customer] " +
  87.                         "ON [Firma3 A_S$Ship-to Address].[Customer No_] = [Firma3 A_S$Customer].[No_] " +
  88.                         "WHERE [Firma3 A_S$Ship-to Address].[Last Date Modified] >= '" + dato + "' " +
  89.                         "OR [Firma3 A_S$Customer].[Last Date Modified] >= '" + dato + "'";
  90.                    
  91.                 }
  92.                 else if (fakturering)
  93.                 {
  94.                     SQLData = "SELECT No_, Name, [Name 2], Address, [Address 2], [Post Code], City, [Country_Region Code] " +
  95.                          "FROM [Firma3 A_S$Customer] " +
  96.                          "WHERE [Firma3 A_S$Customer].[Last Date Modified]>='" + dato + "'";
  97.                 }
  98.                 firma = "firma3";
  99.             }
  100.             else if (firma2Button.Checked)
  101.             {
  102.                 if (levering)
  103.                 {
  104.                     SQLData = "SELECT [Customer No_], [Firma2 A_S$Ship-to address].Name, [Firma2 A_S$Ship-to address].[Name 2], [Firma2 A_S$Ship-to address].Address, [Firma2 A_S$Ship-to address].[Address 2], [Firma2 A_S$Ship-to address].[Post Code], [Firma2 A_S$Ship-to address].City, [Firma2 A_S$Ship-to address].[Country_Region Code] " +
  105.                         "FROM [Firma2 A_S$Ship-to Address] " +
  106.                         "LEFT JOIN [Firma2 A_S$Customer] " +
  107.                         "ON [Firma2 A_S$Ship-to Address].[Customer No_] = [Firma2 A_S$Customer].[No_] " +
  108.                         "WHERE [Firma2 A_S$Ship-to Address].[Last Date Modified] >= '" + dato + "' " +
  109.                         "OR [Firma2 A_S$Customer].[Last Date Modified] >= '" + dato + "'";
  110.                 }
  111.                 else if (fakturering)
  112.                 {
  113.                     SQLData = "SELECT No_, Name, [Name 2], Address, [Address 2], [Post Code], City, [Country_Region Code] " +
  114.                               "FROM [Firma2 A_S$Customer] " +
  115.                               "WHERE [Firma2 A_S$Customer].[Last Date Modified]>='" + dato + "'";
  116.                 }
  117.                 firma = "firma2";
  118.             }
  119.             if (levering)
  120.             {
  121.                 try
  122.                 {
  123.                     SqlDataReader myReader = null;
  124.                     SqlCommand myCommand = new SqlCommand(SQLData, myConnection);
  125.                     myReader = myCommand.ExecuteReader();
  126.                     TextWriter TW = new StreamWriter(@"c:\" +firma+"lev.txt");
  127.                     while (myReader.Read())
  128.                     {
  129.                         string customer = myReader["Customer No_"].ToString() + ",";
  130.                         customer += myReader["Name"].ToString() + ",";
  131.                         customer += myReader["Address"].ToString() + ",";
  132.                         customer += myReader["Address 2"].ToString() + ",";
  133.                         customer += myReader["Post Code"].ToString() + ",";
  134.                         customer += myReader["City"].ToString() + ",";
  135.                         customer += myReader["Country_Region Code"].ToString() + ",,,,,";
  136.                         TW.WriteLine(customer);
  137.  
  138.                     }
  139.                     MessageBox.Show(firma + "s leveringsadresser er nu gemt i c:\\" + firma + "lev.txt");
  140.                     filnavn = "c:\\" + firma + "lev.txt";
  141.                    
  142.                     TW.Close();
  143.                     myConnection.Close();
  144.                 }
  145.                 catch (Exception f)
  146.                 {
  147.                     MessageBox.Show(f.ToString());
  148.                 }
  149.             }
  150.             else if (fakturering)
  151.             {
  152.                 try
  153.                 {
  154.                     SqlDataReader myReader = null;
  155.                     SqlCommand myCommand = new SqlCommand(SQLData, myConnection);
  156.                     myReader = myCommand.ExecuteReader();
  157.                     TextWriter TW = new StreamWriter(@"c:\" + firma + "nolev.txt");
  158.                     while (myReader.Read())
  159.                     {
  160.                         string customer = myReader["No_"].ToString() + ",";
  161.                         customer += myReader["Name"].ToString() + ",";
  162.                         customer += myReader["Address"].ToString() + ",";
  163.                         customer += myReader["Address 2"].ToString() + ",";
  164.                         customer += myReader["Post Code"].ToString() + ",";
  165.                         customer += myReader["City"].ToString() + ",";
  166.                         customer += myReader["Country_Region Code"].ToString() + ",,,,,";
  167.                         TW.WriteLine(customer);
  168.                     }
  169.                     MessageBox.Show(firma + "s leveringsadresser er nu gemt i c:\\" + firma + "nolev.txt");
  170.                     filnavn = "c:\\" + firma + "nolev.txt";
  171.                     TW.Close();
  172.                     myConnection.Close();
  173.                 }
  174.                 catch (Exception f)
  175.                 {
  176.                     MessageBox.Show(f.ToString());
  177.                 }
  178.             }
  179.  
  180.             var codes = new Dictionary<string, string>();
  181.             {
  182.                 codes.Add(",AD,", ",43,");  codes.Add(",AE,", ",647,"); codes.Add(",AG,", ",459,");
  183.                 codes.Add(",AI,", ",446,"); codes.Add(",AL,", ",70,");  codes.Add(",AM,", ",77,");
  184.                 codes.Add(",AN,", ",478,"); codes.Add(",AO,", ",330,"); codes.Add(",AR,", ",528,");
  185.                 codes.Add(",AT,", ",38,");  codes.Add(",AU,", ",800,"); codes.Add(",AW,", ",474,");
  186.                 codes.Add(",AZ,", ",78,");  codes.Add(",BA,", ",93,");  codes.Add(",BB,", ",469,");
  187.                 codes.Add(",BD,", ",666,"); codes.Add(",BE,", ",2,");   codes.Add(",BF,", ",236,");
  188.                 codes.Add(",BG,", ",100,"); codes.Add(",BH,", ",640,"); codes.Add(",BI,", ",328,");
  189.                 codes.Add(",BJ,", ",284,"); codes.Add(",BM,", ",413,"); codes.Add(",BN,", ",703,");
  190.                 codes.Add(",BO,", ",516,"); codes.Add(",BR,", ",508,"); codes.Add(",BS,", ",453,");
  191.                 codes.Add(",BT,", ",675,"); codes.Add(",BW,", ",391,"); codes.Add(",BY,", ",73,");
  192.                 codes.Add(",BZ,", ",421,"); codes.Add(",CA,", ",404,"); codes.Add(",CD,", ",322,");
  193.                 codes.Add(",CF,", ",306,"); codes.Add(",CG,", ",318,"); codes.Add(",CH,", ",39,");
  194.                 codes.Add(",CI,", ",272,"); codes.Add(",CL,", ",512,"); codes.Add(",CM,", ",302,");
  195.                 codes.Add(",CN,", ",720,"); codes.Add(",CO,", ",480,"); codes.Add(",CS,", ",98,");
  196.                 codes.Add(",CV,", ",247,"); codes.Add(",CY,", ",196,"); codes.Add(",CZ,", ",61,");
  197.                 codes.Add(",DE,", ",4,");   codes.Add(",DJ,", ",338,"); codes.Add(",DK,", ",8,");
  198.                 codes.Add(",DM,", ",460,"); codes.Add(",DO,", ",456,"); codes.Add(",DZ,", ",208,");
  199.                 codes.Add(",EC,", ",500,"); codes.Add(",EE,", ",233,"); codes.Add(",EG,", ",220,");
  200.                 codes.Add(",ER,", ",336,"); codes.Add(",ES,", ",11,");  codes.Add(",ET,", ",334,");
  201.                 codes.Add(",FI,", ",32,");  codes.Add(",FJ,", ",815,"); codes.Add(",FM,", ",823,");
  202.                 codes.Add(",FO,", ",234,"); codes.Add(",FR,", ",1,");   codes.Add(",GA,", ",314,");
  203.                 codes.Add(",GB,", ",6,");   codes.Add(",GD,", ",473,"); codes.Add(",GE,", ",76,");
  204.                 codes.Add(",GH,", ",276,"); codes.Add(",GI,", ",292,"); codes.Add(",GL,", ",304,");
  205.                 codes.Add(",GM,", ",252,"); codes.Add(",GN,", ",260,"); codes.Add(",GQ,", ",310,");
  206.                 codes.Add(",GR,", ",9,");   codes.Add(",GT,", ",416,"); codes.Add(",GW,", ",257,");
  207.                 codes.Add(",GY,", ",488,"); codes.Add(",HK,", ",740,"); codes.Add(",HN,", ",424,");
  208.                 codes.Add(",HR,", ",92,");  codes.Add(",HT,", ",452,"); codes.Add(",HU,", ",64,");
  209.                 codes.Add(",ID,", ",700,"); codes.Add(",IE,", ",7,");   codes.Add(",IL,", ",624,");
  210.                 codes.Add(",IN,", ",664,"); codes.Add(",IQ,", ",612,"); codes.Add(",IR,", ",616,");
  211.                 codes.Add(",IS,", ",352,"); codes.Add(",IT,", ",5,");   codes.Add(",JM,", ",464,");
  212.                 codes.Add(",JO,", ",628,"); codes.Add(",JP,", ",732,"); codes.Add(",KE,", ",346,");
  213.                 codes.Add(",KG,", ",83,");  codes.Add(",KH,", ",696,"); codes.Add(",KN,", ",449,");
  214.                 codes.Add(",KW,", ",636,"); codes.Add(",KY,", ",436,"); codes.Add(",KZ,", ",79,");
  215.                 codes.Add(",LA,", ",684,"); codes.Add(",LB,", ",604,"); codes.Add(",LC,", ",465,");
  216.                 codes.Add(",LK,", ",669,"); codes.Add(",LR,", ",268,"); codes.Add(",LS,", ",395,");
  217.                 codes.Add(",LT,", ",440,"); codes.Add(",LU,", ",19,");  codes.Add(",LV,", ",428,");
  218.                 codes.Add(",LY,", ",216,"); codes.Add(",MA,", ",204,"); codes.Add(",MC,", ",492,");
  219.                 codes.Add(",MD,", ",74,");  codes.Add(",MG,", ",370,"); codes.Add(",MH,", ",824,");
  220.                 codes.Add(",MK,", ",96,");  codes.Add(",ML,", ",232,"); codes.Add(",MM,", ",676,");
  221.                 codes.Add(",MN,", ",716,"); codes.Add(",MO,", ",743,"); codes.Add(",MP,", ",820,");
  222.                 codes.Add(",MR,", ",228,"); codes.Add(",MS,", ",470,"); codes.Add(",MT,", ",46,");
  223.                 codes.Add(",MU,", ",373,"); codes.Add(",MV,", ",667,"); codes.Add(",MW,", ",386,");
  224.                 codes.Add(",MX,", ",412,"); codes.Add(",MY,", ",701,"); codes.Add(",MZ,", ",366,");
  225.                 codes.Add(",NA,", ",389,"); codes.Add(",NC,", ",809,"); codes.Add(",NE,", ",240,");
  226.                 codes.Add(",NG,", ",288,"); codes.Add(",NI,", ",432,"); codes.Add(",NL,", ",3,");
  227.                 codes.Add(",NO,", ",28,");  codes.Add(",NP,", ",672,"); codes.Add(",NZ,", ",804,");
  228.                 codes.Add(",OM,", ",649,"); codes.Add(",PA,", ",442,"); codes.Add(",PF,", ",822,");
  229.                 codes.Add(",PG,", ",801,"); codes.Add(",PH,", ",708,"); codes.Add(",PK,", ",662,");
  230.                 codes.Add(",PL,", ",60,");  codes.Add(",PT,", ",10,");  codes.Add(",PW,", ",825,");
  231.                 codes.Add(",PY,", ",520,"); codes.Add(",QA,", ",644,"); codes.Add(",RE,", ",638,");
  232.                 codes.Add(",RO,", ",66,");  codes.Add(",RU,", ",75,");  codes.Add(",RW,", ",324,");
  233.                 codes.Add(",SA,", ",632,"); codes.Add(",SC,", ",355,"); codes.Add(",SD,", ",224,");
  234.                 codes.Add(",SE,", ",30,");  codes.Add(",SG,", ",706,"); codes.Add(",SI,", ",91,");
  235.                 codes.Add(",SK,", ",63,");  codes.Add(",SL,", ",264,"); codes.Add(",SM,", ",674,");
  236.                 codes.Add(",SN,", ",248,"); codes.Add(",SO,", ",342,"); codes.Add(",SY,", ",608,");
  237.                 codes.Add(",SZ,", ",393,"); codes.Add(",TD,", ",244,"); codes.Add(",TG,", ",280,");
  238.                 codes.Add(",TH,", ",680,"); codes.Add(",TJ,", ",82,");  codes.Add(",TM,", ",80,");
  239.                 codes.Add(",TN,", ",212,"); codes.Add(",TR,", ",52,");  codes.Add(",TT,", ",472,");
  240.                 codes.Add(",TW,", ",736,"); codes.Add(",UA,", ",72,");  codes.Add(",UG,", ",350,");
  241.                 codes.Add(",US,", ",400,"); codes.Add(",UY,", ",524,"); codes.Add(",UZ,", ",81,");
  242.                 codes.Add(",VC,", ",467,"); codes.Add(",VE,", ",484,"); codes.Add(",VG,", ",468,");
  243.                 codes.Add(",VI,", ",457,"); codes.Add(",VN,", ",690,"); codes.Add(",VU,", ",816,");
  244.                 codes.Add(",WF,", ",811,"); codes.Add(",YE,", ",653,"); codes.Add(",ZA,", ",388,");
  245.                 codes.Add(",ZM,", ",378,"); codes.Add(",ZW,", ",382,");
  246.             };
  247.  
  248.             string text = File.ReadAllText(filnavn);
  249.  
  250.             foreach (var code in codes)
  251.             {
  252.                 text = text.Replace(code.Key, code.Value.ToString());
  253.             }
  254.  
  255.             File.WriteAllText(filnavn, text);
  256.             MessageBox.Show("Search/replace er nu færdig. Filen kan indlæses i Interline");
  257.  
  258.  
  259.         }
  260.  
  261.         public void afslutToolStripMenuItem_Click(object sender, EventArgs e)
  262.         {
  263.             Application.Exit();
  264.         }
  265.  
  266.         private void helpToolStripMenuItem_Click(object sender, EventArgs e)
  267.         {
  268.             MessageBox.Show("Vælg firma, hvilken type adresser, dato og tryk start");
  269.         }
  270.  
  271.         private void versionToolStripMenuItem_Click(object sender, EventArgs e)
  272.         {
  273.             MessageBox.Show("Version: " + ApplicationDeployment.CurrentDeployment.CurrentVersion + "\nLavet af :D");
  274.         }
  275.  
  276.  
  277.     }
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement