Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using System.Web;
- using System.IO;
- using System.Deployment;
- using System.Deployment.Application;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SqlConnection myConnection = new SqlConnection("user id=user;" +
- "password=pw;server=server;" +
- "Trusted_Connection=no;" +
- "database=db; " +
- "connection timeout=30");
- try
- {
- myConnection.Open();
- }
- catch (Exception f)
- {
- MessageBox.Show(f.ToString());
- }
- bool fakturering = false;
- bool levering = false;
- string SQLData = "";
- string firma = null;
- string filnavn = null;
- string dato = kalender.SelectionStart.ToString("s");
- dato = dato.Remove(10, 9);
- if (faktureringsButton.Checked)
- {
- fakturering = true;
- }
- else if (leveringsButton.Checked)
- {
- levering = true;
- }
- if (firmaButton.Checked)
- {
- if (levering)
- {
- 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] " +
- "FROM [Firma A_S$Ship-to Address] " +
- "LEFT JOIN [Firma A_S$Customer] " +
- "ON [Firma A_S$Ship-to Address].[Customer No_] = [Firma A_S$Customer].[No_] " +
- "WHERE [Firma A_S$Ship-to Address].[Last Date Modified] >= '" + dato + "' " +
- "OR [Firma A_S$Customer].[Last Date Modified] >= '" + dato + "'";
- }
- else if (fakturering)
- {
- SQLData = "SELECT No_, Name, [Name 2], Address, [Address 2], [Post Code], City, [Country_Region Code] " +
- "FROM [Firma A_S$Customer] " +
- "WHERE [Firma A_S$Customer].[Last Date Modified]>='" + dato + "'";
- }
- firma = "firma";
- }
- else if (firma3Button.Checked)
- {
- if (levering)
- {
- 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] " +
- "FROM [Firma3 A_S$Ship-to Address] " +
- "LEFT JOIN [Firma3 A_S$Customer] " +
- "ON [Firma3 A_S$Ship-to Address].[Customer No_] = [Firma3 A_S$Customer].[No_] " +
- "WHERE [Firma3 A_S$Ship-to Address].[Last Date Modified] >= '" + dato + "' " +
- "OR [Firma3 A_S$Customer].[Last Date Modified] >= '" + dato + "'";
- }
- else if (fakturering)
- {
- SQLData = "SELECT No_, Name, [Name 2], Address, [Address 2], [Post Code], City, [Country_Region Code] " +
- "FROM [Firma3 A_S$Customer] " +
- "WHERE [Firma3 A_S$Customer].[Last Date Modified]>='" + dato + "'";
- }
- firma = "firma3";
- }
- else if (firma2Button.Checked)
- {
- if (levering)
- {
- 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] " +
- "FROM [Firma2 A_S$Ship-to Address] " +
- "LEFT JOIN [Firma2 A_S$Customer] " +
- "ON [Firma2 A_S$Ship-to Address].[Customer No_] = [Firma2 A_S$Customer].[No_] " +
- "WHERE [Firma2 A_S$Ship-to Address].[Last Date Modified] >= '" + dato + "' " +
- "OR [Firma2 A_S$Customer].[Last Date Modified] >= '" + dato + "'";
- }
- else if (fakturering)
- {
- SQLData = "SELECT No_, Name, [Name 2], Address, [Address 2], [Post Code], City, [Country_Region Code] " +
- "FROM [Firma2 A_S$Customer] " +
- "WHERE [Firma2 A_S$Customer].[Last Date Modified]>='" + dato + "'";
- }
- firma = "firma2";
- }
- if (levering)
- {
- try
- {
- SqlDataReader myReader = null;
- SqlCommand myCommand = new SqlCommand(SQLData, myConnection);
- myReader = myCommand.ExecuteReader();
- TextWriter TW = new StreamWriter(@"c:\" +firma+"lev.txt");
- while (myReader.Read())
- {
- string customer = myReader["Customer No_"].ToString() + ",";
- customer += myReader["Name"].ToString() + ",";
- customer += myReader["Address"].ToString() + ",";
- customer += myReader["Address 2"].ToString() + ",";
- customer += myReader["Post Code"].ToString() + ",";
- customer += myReader["City"].ToString() + ",";
- customer += myReader["Country_Region Code"].ToString() + ",,,,,";
- TW.WriteLine(customer);
- }
- MessageBox.Show(firma + "s leveringsadresser er nu gemt i c:\\" + firma + "lev.txt");
- filnavn = "c:\\" + firma + "lev.txt";
- TW.Close();
- myConnection.Close();
- }
- catch (Exception f)
- {
- MessageBox.Show(f.ToString());
- }
- }
- else if (fakturering)
- {
- try
- {
- SqlDataReader myReader = null;
- SqlCommand myCommand = new SqlCommand(SQLData, myConnection);
- myReader = myCommand.ExecuteReader();
- TextWriter TW = new StreamWriter(@"c:\" + firma + "nolev.txt");
- while (myReader.Read())
- {
- string customer = myReader["No_"].ToString() + ",";
- customer += myReader["Name"].ToString() + ",";
- customer += myReader["Address"].ToString() + ",";
- customer += myReader["Address 2"].ToString() + ",";
- customer += myReader["Post Code"].ToString() + ",";
- customer += myReader["City"].ToString() + ",";
- customer += myReader["Country_Region Code"].ToString() + ",,,,,";
- TW.WriteLine(customer);
- }
- MessageBox.Show(firma + "s leveringsadresser er nu gemt i c:\\" + firma + "nolev.txt");
- filnavn = "c:\\" + firma + "nolev.txt";
- TW.Close();
- myConnection.Close();
- }
- catch (Exception f)
- {
- MessageBox.Show(f.ToString());
- }
- }
- var codes = new Dictionary<string, string>();
- {
- codes.Add(",AD,", ",43,"); codes.Add(",AE,", ",647,"); codes.Add(",AG,", ",459,");
- codes.Add(",AI,", ",446,"); codes.Add(",AL,", ",70,"); codes.Add(",AM,", ",77,");
- codes.Add(",AN,", ",478,"); codes.Add(",AO,", ",330,"); codes.Add(",AR,", ",528,");
- codes.Add(",AT,", ",38,"); codes.Add(",AU,", ",800,"); codes.Add(",AW,", ",474,");
- codes.Add(",AZ,", ",78,"); codes.Add(",BA,", ",93,"); codes.Add(",BB,", ",469,");
- codes.Add(",BD,", ",666,"); codes.Add(",BE,", ",2,"); codes.Add(",BF,", ",236,");
- codes.Add(",BG,", ",100,"); codes.Add(",BH,", ",640,"); codes.Add(",BI,", ",328,");
- codes.Add(",BJ,", ",284,"); codes.Add(",BM,", ",413,"); codes.Add(",BN,", ",703,");
- codes.Add(",BO,", ",516,"); codes.Add(",BR,", ",508,"); codes.Add(",BS,", ",453,");
- codes.Add(",BT,", ",675,"); codes.Add(",BW,", ",391,"); codes.Add(",BY,", ",73,");
- codes.Add(",BZ,", ",421,"); codes.Add(",CA,", ",404,"); codes.Add(",CD,", ",322,");
- codes.Add(",CF,", ",306,"); codes.Add(",CG,", ",318,"); codes.Add(",CH,", ",39,");
- codes.Add(",CI,", ",272,"); codes.Add(",CL,", ",512,"); codes.Add(",CM,", ",302,");
- codes.Add(",CN,", ",720,"); codes.Add(",CO,", ",480,"); codes.Add(",CS,", ",98,");
- codes.Add(",CV,", ",247,"); codes.Add(",CY,", ",196,"); codes.Add(",CZ,", ",61,");
- codes.Add(",DE,", ",4,"); codes.Add(",DJ,", ",338,"); codes.Add(",DK,", ",8,");
- codes.Add(",DM,", ",460,"); codes.Add(",DO,", ",456,"); codes.Add(",DZ,", ",208,");
- codes.Add(",EC,", ",500,"); codes.Add(",EE,", ",233,"); codes.Add(",EG,", ",220,");
- codes.Add(",ER,", ",336,"); codes.Add(",ES,", ",11,"); codes.Add(",ET,", ",334,");
- codes.Add(",FI,", ",32,"); codes.Add(",FJ,", ",815,"); codes.Add(",FM,", ",823,");
- codes.Add(",FO,", ",234,"); codes.Add(",FR,", ",1,"); codes.Add(",GA,", ",314,");
- codes.Add(",GB,", ",6,"); codes.Add(",GD,", ",473,"); codes.Add(",GE,", ",76,");
- codes.Add(",GH,", ",276,"); codes.Add(",GI,", ",292,"); codes.Add(",GL,", ",304,");
- codes.Add(",GM,", ",252,"); codes.Add(",GN,", ",260,"); codes.Add(",GQ,", ",310,");
- codes.Add(",GR,", ",9,"); codes.Add(",GT,", ",416,"); codes.Add(",GW,", ",257,");
- codes.Add(",GY,", ",488,"); codes.Add(",HK,", ",740,"); codes.Add(",HN,", ",424,");
- codes.Add(",HR,", ",92,"); codes.Add(",HT,", ",452,"); codes.Add(",HU,", ",64,");
- codes.Add(",ID,", ",700,"); codes.Add(",IE,", ",7,"); codes.Add(",IL,", ",624,");
- codes.Add(",IN,", ",664,"); codes.Add(",IQ,", ",612,"); codes.Add(",IR,", ",616,");
- codes.Add(",IS,", ",352,"); codes.Add(",IT,", ",5,"); codes.Add(",JM,", ",464,");
- codes.Add(",JO,", ",628,"); codes.Add(",JP,", ",732,"); codes.Add(",KE,", ",346,");
- codes.Add(",KG,", ",83,"); codes.Add(",KH,", ",696,"); codes.Add(",KN,", ",449,");
- codes.Add(",KW,", ",636,"); codes.Add(",KY,", ",436,"); codes.Add(",KZ,", ",79,");
- codes.Add(",LA,", ",684,"); codes.Add(",LB,", ",604,"); codes.Add(",LC,", ",465,");
- codes.Add(",LK,", ",669,"); codes.Add(",LR,", ",268,"); codes.Add(",LS,", ",395,");
- codes.Add(",LT,", ",440,"); codes.Add(",LU,", ",19,"); codes.Add(",LV,", ",428,");
- codes.Add(",LY,", ",216,"); codes.Add(",MA,", ",204,"); codes.Add(",MC,", ",492,");
- codes.Add(",MD,", ",74,"); codes.Add(",MG,", ",370,"); codes.Add(",MH,", ",824,");
- codes.Add(",MK,", ",96,"); codes.Add(",ML,", ",232,"); codes.Add(",MM,", ",676,");
- codes.Add(",MN,", ",716,"); codes.Add(",MO,", ",743,"); codes.Add(",MP,", ",820,");
- codes.Add(",MR,", ",228,"); codes.Add(",MS,", ",470,"); codes.Add(",MT,", ",46,");
- codes.Add(",MU,", ",373,"); codes.Add(",MV,", ",667,"); codes.Add(",MW,", ",386,");
- codes.Add(",MX,", ",412,"); codes.Add(",MY,", ",701,"); codes.Add(",MZ,", ",366,");
- codes.Add(",NA,", ",389,"); codes.Add(",NC,", ",809,"); codes.Add(",NE,", ",240,");
- codes.Add(",NG,", ",288,"); codes.Add(",NI,", ",432,"); codes.Add(",NL,", ",3,");
- codes.Add(",NO,", ",28,"); codes.Add(",NP,", ",672,"); codes.Add(",NZ,", ",804,");
- codes.Add(",OM,", ",649,"); codes.Add(",PA,", ",442,"); codes.Add(",PF,", ",822,");
- codes.Add(",PG,", ",801,"); codes.Add(",PH,", ",708,"); codes.Add(",PK,", ",662,");
- codes.Add(",PL,", ",60,"); codes.Add(",PT,", ",10,"); codes.Add(",PW,", ",825,");
- codes.Add(",PY,", ",520,"); codes.Add(",QA,", ",644,"); codes.Add(",RE,", ",638,");
- codes.Add(",RO,", ",66,"); codes.Add(",RU,", ",75,"); codes.Add(",RW,", ",324,");
- codes.Add(",SA,", ",632,"); codes.Add(",SC,", ",355,"); codes.Add(",SD,", ",224,");
- codes.Add(",SE,", ",30,"); codes.Add(",SG,", ",706,"); codes.Add(",SI,", ",91,");
- codes.Add(",SK,", ",63,"); codes.Add(",SL,", ",264,"); codes.Add(",SM,", ",674,");
- codes.Add(",SN,", ",248,"); codes.Add(",SO,", ",342,"); codes.Add(",SY,", ",608,");
- codes.Add(",SZ,", ",393,"); codes.Add(",TD,", ",244,"); codes.Add(",TG,", ",280,");
- codes.Add(",TH,", ",680,"); codes.Add(",TJ,", ",82,"); codes.Add(",TM,", ",80,");
- codes.Add(",TN,", ",212,"); codes.Add(",TR,", ",52,"); codes.Add(",TT,", ",472,");
- codes.Add(",TW,", ",736,"); codes.Add(",UA,", ",72,"); codes.Add(",UG,", ",350,");
- codes.Add(",US,", ",400,"); codes.Add(",UY,", ",524,"); codes.Add(",UZ,", ",81,");
- codes.Add(",VC,", ",467,"); codes.Add(",VE,", ",484,"); codes.Add(",VG,", ",468,");
- codes.Add(",VI,", ",457,"); codes.Add(",VN,", ",690,"); codes.Add(",VU,", ",816,");
- codes.Add(",WF,", ",811,"); codes.Add(",YE,", ",653,"); codes.Add(",ZA,", ",388,");
- codes.Add(",ZM,", ",378,"); codes.Add(",ZW,", ",382,");
- };
- string text = File.ReadAllText(filnavn);
- foreach (var code in codes)
- {
- text = text.Replace(code.Key, code.Value.ToString());
- }
- File.WriteAllText(filnavn, text);
- MessageBox.Show("Search/replace er nu færdig. Filen kan indlæses i Interline");
- }
- public void afslutToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void helpToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Vælg firma, hvilken type adresser, dato og tryk start");
- }
- private void versionToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Version: " + ApplicationDeployment.CurrentDeployment.CurrentVersion + "\nLavet af :D");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement