root/Baza Reklam 2 - Faktury/OferForm.cs @ 28

Wersja 2, 8.3 KB (wprowadzona przez dorota, 17 years temu)
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.IO;
9
10
11namespace Baza_Reklam
12{
13    public partial class OferForm : Form
14    {
15        int customerId;
16        int ofertaId;
17        bool nowa = false;
18
19        public int CustomerId
20        {
21            get { return customerId; }
22            set { customerId = value; }
23        }
24       
25        public OferForm(int custId,int ofertaID,bool nowa)
26        {
27            InitializeComponent();
28            this.customerId = custId;
29            this.ofertaId = ofertaID;
30            this.nowa = nowa;
31
32            oFERTY_MAINTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
33            oferty_WersjeTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
34            kLIENCI_OSOBY_DO_KONTAKTUTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
35            kLIENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
36            rEKLAMATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
37            pRODUKCJATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
38            jezyki_defTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
39            lISTA_TYTULOWTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
40            aGENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
41        }
42
43        private void OferForm_Load(object sender, EventArgs e)
44        {
45            if (this.nowa)
46            {
47                DataView table = (DataView) this.oFERTY_MAINBindingSource.List;
48                DataRowView row = table.AddNew();
49
50                row["CUSTOMER_ID"] = this.customerId;
51                row["AGENT"] = User.getUser().Login;
52                row["Data_Oferty"] = DateTime.Today;
53                row["Data_Wyslania"] = DateTime.Today;
54                row["Data_Modyfikacji"] = DateTime.Today;
55                row["Zmodyfikowal_User"] = User.getUser().Login;
56
57                this.oFERTY_MAINBindingSource.EndEdit();
58                this.oFERTY_MAINTableAdapter.Update(this.rEKLAMADataSet.OFERTY_MAIN);
59                this.oFERTY_MAINBindingSource.MoveLast();
60            }
61            else
62            {             
63                this.oFERTY_MAINTableAdapter.FillByIdOferty(this.rEKLAMADataSet.OFERTY_MAIN, this.ofertaId);
64            }
65 
66            this.aGENCITableAdapter.Fill(this.sLOWNIKDataSet.AGENCI);
67
68            this.kLIENCI_OSOBY_DO_KONTAKTUTableAdapter.FillByCustomerId(this.rEKLAMADataSet.KLIENCI_OSOBY_DO_KONTAKTU,this.customerId);
69            this.kLIENCITableAdapter.FillByCustomerId(this.rEKLAMADataSet.KLIENCI,this.customerId);
70            this.rEKLAMATableAdapter.FillByCustomerId(this.rEKLAMADataSet.REKLAMA,this.customerId);
71
72            foreach (DataRowView r in rEKLAMABindingSource.List)
73            {
74                this.pRODUKCJATableAdapter.ClearBeforeFill = false;
75                this.pRODUKCJATableAdapter.FillByReklamaId(this.rEKLAMADataSet.PRODUKCJA,Convert.ToInt32(r["reklamaId"]));
76            }
77
78            this.jezyki_defTableAdapter.Fill(this.sLOWNIKDataSet.jezyki_def);
79            this.oferty_WersjeTableAdapter.Fill(this.rEKLAMADataSet.Oferty_Wersje);
80            this.lISTA_TYTULOWTableAdapter.Fill(this.sLOWNIKDataSet.LISTA_TYTULOW);         
81
82            this.oFERTY_MAINBindingSource.ResetBindings(false);
83           
84        }
85
86        private void pokOferteButton_Click(object sender, EventArgs e)
87        {
88            this.Cursor = Cursors.WaitCursor;
89
90            this.oFERTY_MAINBindingSource.EndEdit();
91            this.oFERTY_MAINTableAdapter.Update(this.rEKLAMADataSet.OFERTY_MAIN);
92
93            DataRowView r = (DataRowView)oFERTY_MAINBindingSource.Current;
94            //string katalog = @"C:\Users\Dorota\Desktop\Wzory_Pism\";
95            string katalog1 = @"g:\reklamafiles\oferty\Wzory_Pism\";
96            string katalog2 = @"g:\reklamafiles\oferty\";
97
98           
99
100            if (Convert.ToInt32(r["zapisana"]) == 0)
101            {
102                if (ofertyWersjeBindingSource.Current != null)
103                {
104                    DataRowView row = (DataRowView)ofertyWersjeBindingSource.Current;
105
106                    string filename = katalog1 + row["nazwa_pliku"].ToString();
107                    string newFileName = katalog2 + r["id_oferty"].ToString() + ".doc";
108
109                    if (File.Exists(filename))
110                    {
111                        CreateNewOfer(filename, newFileName);
112
113                        r["zapisana"] = -1;
114                        oFERTY_MAINBindingSource.EndEdit();
115                        oFERTY_MAINTableAdapter.Update(this.rEKLAMADataSet.OFERTY_MAIN);
116                    }
117                    else
118                    {
119                        MessageBox.Show("Nie istnieje wybrana oferta.");
120                    }
121                }       
122            }
123            else
124            {
125                string filename = katalog2 + r["id_oferty"].ToString() + ".doc";
126
127                if (File.Exists(filename))
128                {
129                    OpenOfer(filename);
130                }
131                else
132                {
133                    MessageBox.Show("Nie mo¿na odnale¿æ pliku z ofert¹.");
134                }               
135            }
136            this.Cursor = Cursors.Default;
137        }
138
139        private static void OpenOfer(string filename)
140        {
141            WordHandler wh = new WordHandler();
142
143            wh.openFile(filename);
144            wh.setWordVisible();
145        }
146
147        private void CreateNewOfer(string filename, string newFileName)
148        {
149            WordHandler wh = new WordHandler();
150
151            wh.openFile(filename);
152
153            wh.findAndReplace("<<Oferta_Numer>>", id_ofertyTextBox.Text + "/" + User.getUser().Kod_agenta.ToUpper() + "/" + DateTime.Today.Year);
154            wh.findAndReplace("<<Osoba_Do_Kontaktu>>", id_klienci_os_kontaktComboBox.Text);
155            wh.findAndReplace("<<Nazwa_i_Adres_Klienta>>", adres_KorTextBox.Text);
156            wh.findAndReplace("<<Miasto>>", User.getUser().Miasto);
157            wh.findAndReplace("<<Data_Oferty>>", data_OfertyDateTimePicker.Value.ToShortDateString());
158            wh.findAndReplace("<<Podpis_Agenta>>", User.getUser().Imie + " " + User.getUser().Nazwisko);
159            wh.findAndReplace("<<Email_Agenta>>", User.getUser().Email);
160            wh.findAndReplace("<<tel_wew_Agenta>>", User.getUser().TelWewnetrzny);
161            wh.findAndReplace("<<tel_mobile_Agenta>>", User.getUser().KomSluzbowa);
162            wh.findAndReplace("<<Adres_Biura>>", User.getUser().AdresBiura);
163            wh.findAndReplace("<<Tel_Biura>>", User.getUser().TelSekretariat);
164            wh.findAndReplace("<<Fax_Biura>>", User.getUser().FaxSekretariat);
165            wh.findAndReplace("<<Oferta_Opis_Dod>>", opis_DolTextBox.Text);
166            wh.findAndReplace("<<Stanowisko_Agenta>>", User.getUser().Stanowisko);
167
168            wh.saveAs(newFileName);
169
170            wh.setWordVisible();
171        }
172
173        private void zapiszButton_Click(object sender, EventArgs e)
174        {
175            DataRowView row = (DataRowView)oFERTY_MAINBindingSource.Current;
176           
177            row["Data_Modyfikacji"] = DateTime.Today;
178            row["Zmodyfikowal_User"] = User.getUser().Login;
179
180            this.oFERTY_MAINBindingSource.EndEdit();
181            this.oFERTY_MAINTableAdapter.Update(this.rEKLAMADataSet.OFERTY_MAIN);
182        }
183
184        private void anulujButton_Click(object sender, EventArgs e)
185        {
186           this.rEKLAMADataSet.OFERTY_MAIN.RejectChanges();
187        }
188               
189        private void id_tytulComboBox_SelectedValueChanged(object sender, EventArgs e)
190        {
191            if (id_tytulComboBox.SelectedValue != null)
192            {
193                ofertyWersjeBindingSource.Filter = "[id_tytul]=" + id_tytulComboBox.SelectedValue.ToString();
194            }
195        }
196
197        private void OferForm_Shown(object sender, EventArgs e)
198        {
199            id_tytulComboBox.SelectedIndex = -1;
200            oFERTY_MAINBindingSource.ResetBindings(false);
201        }
202
203    }
204}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.