Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
using System;
using System.Web;
using M3Workflow.Data;
using M3Workflow.Data.Base;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using DocuWare.Platform.ServerClient;
using DocuWare.WebIntegration;
using System.Data.SqlClient;
using System.Threading;

namespace M3Workflow.Web
{
    public partial class Default : System.Web.UI.Page
    {
        public new UserDataObject User { get; set; }
        public int EnterpriseIndex { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.User = (UserDataObject)Session["UserDataObject"];
                if (this.User == null)
                    Response.Redirect(String.Format("Login.aspx?errorMessage={0}", HttpUtility.UrlEncode("Unable to access the asp.net session.")));
            }
            catch
            {
                Response.Redirect(String.Format("Login.aspx?errorMessage={0}", "Unable to verify your credentials."));
            }
            this.labelUserName.Text = String.Format("Welcome, {0}", this.User.UserName.Name);
            if (Request.QueryString["propertyId"] != null && Request.QueryString["propertyName"] != null && Request.QueryString["enterpriseIndex"] != null)
            {
                this.propertyName.InnerText = Request.QueryString["propertyName"];
                this.EnterpriseIndex = Convert.ToInt32(Request.QueryString["enterpriseIndex"]);
                this.FileUploadIndex.Visible = true;
                this.FileUploadNoIndex.Visible = true;
                this.postIndex.Visible = true;
                this.postNoIndex.Visible = true;
                this.labelErrorIndex.Visible = true;
                this.labelErrorNoIndex.Visible = true;
                if (Request.QueryString["customerId"] != null && Request.QueryString["companyId"] != null)
                {
                    var customer = this.User.Customers[
                        EnterpriseIndex
                    ];
                    //var customer = (from c in this.User.Customers where c.Id.ToString() == Request.QueryString["customerId"] select c).SingleOrDefault();
                    if (customer != null)
                    {
                        try
                        {
                            this.User.Roles = M3DataProvider.GetRolesByCustomerId(this.User.Token, customer.Id).Roles;
                            this.User.ParseRoles();
                            this.User.AssignGroups();
                            this.User.AssignRoles(EnterpriseIndex);
                        }
                        catch
                        {
                            Response.Redirect(String.Format("Login.aspx?errorMessage={0}", HttpUtility.UrlEncode("Unable to access the asp.net session.")));
                        }
                    }


                    try
                    {
                        BuildLists(
                            Request.QueryString["cabinetName"],
                            Guid.Parse(Request.QueryString["customerId"]),
                            Guid.Parse(Request.QueryString["companyId"]),
                            Guid.Parse(Request.QueryString["propertyId"])
                        );
                        BuildViews(
                            Request.QueryString["cabinetName"],
                            Guid.Parse(Request.QueryString["customerId"]),
                            Request.QueryString["customerName"],
                            Guid.Parse(Request.QueryString["companyId"]),
                            Request.QueryString["companyName"],
                            Guid.Parse(Request.QueryString["propertyId"]),
                            Request.QueryString["propertyName"]
                        );
                    }
                    catch (Exception ex)
                    {
                        this.FileUploadIndex.Visible = false;
                        this.FileUploadNoIndex.Visible = false;
                        this.postIndex.Visible = false;
                        this.postNoIndex.Visible = false;
                        this.labelErrorIndex.Visible = false;
                        this.labelErrorNoIndex.Visible = false;
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            else
            {
                this.FileUploadIndex.Visible = false;
                this.FileUploadNoIndex.Visible = false;
                this.postIndex.Visible = false;
                this.postNoIndex.Visible = false;
                this.labelErrorIndex.Visible = false;
                this.labelErrorNoIndex.Visible = false;
            }
            this.btnGoToWorkflow.Visible = false;
            this.btnGoToWorkflow.Disabled = true;
            this.BuildMenu();
            this.SetPageState();
        }

        private void SetPageState()
        {
            if (Request.QueryString["propertyId"] != null && Request.QueryString["propertyName"] != null && Request.QueryString["enterpriseIndex"] != null)
            {
                foreach (UserRoleObject role in ((UserDataObject)Session["UserDataObject"]).Roles)

                {
                    if (role.RoleName == "Intelligent Indexing Originator" && role.IsMember)
                    {
                        // scanner
                        h3ii.Attributes.Remove("hidden");
                        boxii.Attributes.Remove("hidden");

                        boxmi.Attributes.Add("hidden", "hidden");
                        h3mi.Attributes.Add("hidden", "hidden");

                        btnGoToDocumentTray.Attributes.Remove("disabled");
                    }
                    if (role.RoleName == "Intelligent Indexing Coder" && role.IsMember)
                    {
                        // coder
                        h3ii.Attributes.Remove("hidden");
                        boxii.Attributes.Remove("hidden");

                        h3mi.Attributes.Remove("hidden");
                        boxmi.Attributes.Remove("hidden");

                        btnGoToDocumentTray.Attributes.Remove("disabled");
                    }
                    if (role.RoleName == "Intelligent Indexing Approver" && role.IsMember)
                    {
                        // approver
                        h3ii.Attributes.Remove("hidden");
                        boxii.Attributes.Remove("hidden");

                        h3mi.Attributes.Remove("hidden");
                        boxmi.Attributes.Remove("hidden");

                        btnGoToDocumentTray.Attributes.Remove("disabled");
                    }
                    if (role.RoleName == "Intelligent Indexing Final Approver" && role.IsMember)
                    {
                        // final
                        h3ii.Attributes.Remove("hidden");
                        boxii.Attributes.Remove("hidden");

                        h3mi.Attributes.Remove("hidden");
                        boxmi.Attributes.Remove("hidden");

                        btnGoToDocumentTray.Attributes.Remove("disabled");
                    }
                    if (role.RoleName == "Intelligent Indexing Administrator" && role.IsMember)
                    {
                        h3ii.Attributes.Remove("hidden");
                        boxii.Attributes.Remove("hidden");

                        h3mi.Attributes.Remove("hidden");
                        boxmi.Attributes.Remove("hidden");

                        btnGoToDocumentTray.Attributes.Remove("disabled");
                    }
                }
            }
            
        }

        private void BuildViews(string cabinetName, Guid customerId, string customerName, Guid companyId, string companyName, Guid propertyId, string propertyName)
        {
            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["IntelligentIndexingWorkflow"].ConnectionString);
            cn.Open();
            SqlCommand cmd = new SqlCommand("usp_CreateSelectListViews", cn);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@CabinetName", cabinetName);
            cmd.Parameters.AddWithValue("@CompanyId", companyId);
            cmd.Parameters.AddWithValue("@CompanyName", companyName);
            cmd.Parameters.AddWithValue("@CustomerId", customerId);
            cmd.Parameters.AddWithValue("@CustomerName", customerName);
            cmd.Parameters.AddWithValue("@PropertyId", propertyId);
            cmd.Parameters.AddWithValue("@PropertyName", propertyName);
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            cn.Close();
            cn.Dispose();
        }

        private void BuildLists(string cabinetName, Guid customerId, Guid companyId, Guid propertyId)
        {
            // fix this later
            string delv = "DELETE FROM [dbo].[" + cabinetName.ToUpper() + "_VENDORS" + "];";
            SqlConnection cndelv = new SqlConnection(ConfigurationManager.ConnectionStrings["IntelligentIndexingWorkflow"].ConnectionString);
            cndelv.Open();
            SqlCommand cmddelv = new SqlCommand(delv, cndelv);
            cmddelv.ExecuteNonQuery();
            cmddelv.Dispose();
            cndelv.Close();
            cndelv.Dispose();



            foreach (VendorObject vendor in M3DataProvider.GetVendors(User.Token, customerId, companyId).Vendors)
            {
                string sql = "IF NOT EXISTS (SELECT 1 FROM [dbo].[" + cabinetName.ToUpper() + "_VENDORS" + "] WHERE ItemValue = '" + vendor.VendorName + "') BEGIN INSERT INTO [dbo].[" + cabinetName.ToUpper() + "_VENDORS" + "] ([Id], [ItemValue]) VALUES (@Id, @ItemValue) END;";
                SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["IntelligentIndexingWorkflow"].ConnectionString);
                cn.Open();
                SqlCommand cmd = new SqlCommand(sql, cn);
                cmd.Parameters.AddWithValue("@ItemValue", vendor.VendorName);
                cmd.Parameters.AddWithValue("@Id", vendor.Id);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }


            foreach (AccountDataObject account in M3DataProvider.GetAccounts(User.Token, customerId, companyId).Accounts)
            {
                String sql = "IF(NOT EXISTS(SELECT TOP 1 Id FROM [IntelligentIndexingWorkflow].[dbo].[" + cabinetName.ToUpper() + "_ACCOUNTS" + "] WHERE CompanyId = @CompanyId AND PropertyId = CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN NULL ELSE @PropertyId END AND CompanyLevel = CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN 'Company' ELSE 'Property' END AND ItemValue =  @ItemValue)) BEGIN INSERT INTO [IntelligentIndexingWorkflow].[dbo].[" + cabinetName.ToUpper() + "_ACCOUNTS" + "] (CompanyId, PropertyId, CompanyLevel, ItemValue)VALUES(@CompanyId, CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN NULL ELSE @PropertyId END, CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN 'Company' ELSE 'Property' END,@ItemValue) END";
                SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["IntelligentIndexingWorkflow"].ConnectionString);
                cn.Open();
                SqlCommand cmd = new SqlCommand(sql, cn);
                cmd.Parameters.AddWithValue("@CompanyId", companyId);
                cmd.Parameters.AddWithValue("@PropertyId", account.PropertyId);
                cmd.Parameters.AddWithValue("@ItemValue", account.AccountDescription);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }

            foreach (AccountDataObject account in M3DataProvider.GetAccountsByProperty(User.Token, customerId, propertyId).Accounts)
            {
                String sql = "IF(NOT EXISTS(SELECT TOP 1 Id FROM [IntelligentIndexingWorkflow].[dbo].[" + cabinetName.ToUpper() + "_ACCOUNTS" + "] WHERE CompanyId = @CompanyId AND PropertyId = CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN NULL ELSE @PropertyId END AND CompanyLevel = CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN 'Company' ELSE 'Property' END AND ItemValue =  @ItemValue)) BEGIN INSERT INTO [IntelligentIndexingWorkflow].[dbo].[" + cabinetName.ToUpper() + "_ACCOUNTS" + "] (CompanyId, PropertyId, CompanyLevel, ItemValue)VALUES(@CompanyId, CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN NULL ELSE @PropertyId END, CASE @PropertyId WHEN '00000000-0000-0000-0000-000000000000' THEN 'Company' ELSE 'Property' END,@ItemValue) END";
                SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["IntelligentIndexingWorkflow"].ConnectionString);
                cn.Open();
                SqlCommand cmd = new SqlCommand(sql, cn);
                cmd.Parameters.AddWithValue("@CompanyId", companyId);
                cmd.Parameters.AddWithValue("@PropertyId", account.PropertyId);
                cmd.Parameters.AddWithValue("@ItemValue", account.AccountDescription);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }

        }

        private void BuildMenu()
        {
            int i = 0;
            if (this.User.Customers.Count > 0)
            {
                foreach (UserCustomerObject customer in this.User.Customers)
                {
                    HtmlGenericControl customer_obj = new HtmlGenericControl("li");
                    customer_obj.Attributes.Add("class", "dropdown-submenu");
                    customer_obj.Attributes.Add("data-type", "customer");
                    customer_obj.Attributes.Add("data-id", customer.Id.ToString());
                    customer_obj.Attributes.Add("data-customer-name", customer.CustomerName);
                    customer_obj.Attributes.Add("data-cabinet", customer.Cabinet);
                    customer_obj.Attributes.Add("data-enterpriseindex", i.ToString());
                    HtmlGenericControl customer_obj_a = new HtmlGenericControl("a");
                    customer_obj_a.Attributes.Add("href", "#");
                    customer_obj_a.InnerText = customer.CustomerName;
                    customer_obj.Controls.Add(customer_obj_a);
                    CompanyCollectionDataObject companies = M3DataProvider.GetCompanies(this.User.Token, customer.Id);
                    if (companies != null && companies.Companies.Count > 0)
                    {
                        HtmlGenericControl company_sub = new HtmlGenericControl("ul");
                        foreach (CompanyObject company in companies.Companies)
                        {
                            HtmlGenericControl company_obj = new HtmlGenericControl("li");
                            company_obj.Attributes.Add("class", "dropdown-submenu");
                            company_obj.Attributes.Add("data-type", "company");
                            company_obj.Attributes.Add("data-id", company.Id.ToString());
                            company_obj.Attributes.Add("data-conpany-name", company.CompanyName);
                            HtmlGenericControl company_obj_a = new HtmlGenericControl("a");
                            company_obj_a.Attributes.Add("href", "#");
                            company_obj_a.InnerText = company.CompanyName;
                            company_obj.Controls.Add(company_obj_a);
                            company_sub.Controls.Add(company_obj);
                            customer_obj.Controls.Add(company_sub);
                            PropertyCollectionDataObject properties = M3DataProvider.GetProperties(this.User.Token, customer.Id, company.Id);



                            if (properties != null && properties.Properties.Count > 0)
                            {
                                HtmlGenericControl property_sub = new HtmlGenericControl("ul");
                                property_sub.Attributes.Add("class", "dropdown-menu");

                                HtmlGenericControl comp_level_item = new HtmlGenericControl("li");
                                comp_level_item.Attributes.Add("data-type", "company-level");
                                comp_level_item.Attributes.Add("data-id", "00000000-0000-0000-0000-000000000000");
                                comp_level_item.Attributes.Add("property-name", company.CompanyName + " - " + "Company Level");

                                HtmlGenericControl comp_level_item_a = new HtmlGenericControl("a");
                                comp_level_item_a.Attributes.Add(
                                    "href",
                                        "Default.aspx?"
                                            + "cabinetName=" + HttpUtility.UrlEncode(customer.Cabinet) + "&"
                                            + "customerId=" + HttpUtility.UrlEncode(customer.Id.ToString()) + "&"
                                            + "customerName=" + HttpUtility.UrlEncode(customer.CustomerName) + "&"
                                            + "companyId=" + HttpUtility.UrlEncode(company.Id.ToString()) + "&"
                                            + "companyName=" + HttpUtility.UrlEncode(company.CompanyName) + "&"
                                            + "propertyId=" + HttpUtility.UrlEncode("00000000-0000-0000-0000-000000000000") + "&"
                                            + "propertyName=" + HttpUtility.UrlEncode(company.CompanyName + " - " + "Company Level") + "&"
                                            + "enterpriseIndex=" + i.ToString()
                                );
                                comp_level_item_a.InnerText = "Company Level";

                                HtmlGenericControl comp_level_sep = new HtmlGenericControl("li");
                                comp_level_sep.Attributes.Add("class", "divider");

                                int cnt = 0;

                                foreach (PropertyObject property in properties.Properties)
                                {
                                    if (cnt == 0)
                                    {
                                        comp_level_item.Controls.Add(comp_level_item_a);
                                        property_sub.Controls.Add(comp_level_item);
                                        property_sub.Controls.Add(comp_level_sep);
                                    }
                                    cnt++;
                                    HtmlGenericControl property_obj = new HtmlGenericControl("li");
                                    //property_obj.Attributes.Add("class", "dropdown-submenu");
                                    property_obj.Attributes.Add("data-type", "property");
                                    property_obj.Attributes.Add("data-id", property.Id.ToString());
                                    property_obj.Attributes.Add("data-property-name", property.PropertyName);
                                    HtmlGenericControl property_obj_a = new HtmlGenericControl("a");
                                    property_obj_a.Attributes.Add(
                                        "href",
                                        "Default.aspx?"
                                            + "cabinetName=" + HttpUtility.UrlEncode(customer.Cabinet) + "&"
                                            + "customerId=" + HttpUtility.UrlEncode(customer.Id.ToString()) + "&"
                                            + "customerName=" + HttpUtility.UrlEncode(customer.CustomerName) + "&"
                                            + "companyId=" + HttpUtility.UrlEncode(company.Id.ToString()) + "&"
                                            + "companyName=" + HttpUtility.UrlEncode(company.CompanyName) + "&"
                                            + "propertyId=" + HttpUtility.UrlEncode(property.Id.ToString()) + "&"
                                            + "propertyName=" + HttpUtility.UrlEncode(property.PropertyName) + "&"
                                            + "enterpriseIndex=" + i.ToString()

                                    );
                                    property_obj_a.InnerText = property.PropertyName;
                                    property_obj.Controls.Add(property_obj_a);
                                    property_sub.Controls.Add(property_obj);
                                    company_obj.Controls.Add(property_sub);
                                }
                            }
                        }
                    }
                    userMenuObject.Controls.Add(customer_obj);
                    i++;
                }
            }
        }

        protected void postNoIndex_Click(object sender, EventArgs e)
        {
            if (FileUploadNoIndex.HasFiles)
            {
                String fileExtension = System.IO.Path.GetExtension(FileUploadNoIndex.FileName).ToLower();
                String[] allowedExtensions = { ".pdf" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        string id = Guid.NewGuid().ToString();
                        if (FileUploadIndex.PostedFile.ContentLength < 1024000)
                        {
                            //FileUploadNoIndex.SaveAs(Path.Combine(Server.MapPath("~/Upload/"), id + "." + FileUploadNoIndex.FileName));
                            FileUploadNoIndex.SaveAs(
                                Path.Combine(
                                    new string[] {
                                        Server.MapPath("~/Upload/"),
                                        Path.GetFileNameWithoutExtension(FileUploadIndex.FileName) + "-" + id + "." + Path.GetExtension(FileUploadIndex.FileName)
                                    }
                                )
                            );
                            labelErrorNoIndex.Visible = true;
                            labelErrorNoIndex.ForeColor = System.Drawing.Color.Green;
                            labelErrorNoIndex.Text = "File Uploaded";
                            //this.addDocument(new FileInfo(Path.Combine(Server.MapPath("~/Upload/"), id + "." + FileUploadNoIndex.FileName)));
                            this.addDocument(
                                new FileInfo(
                                    Path.Combine(
                                        new string[] {
                                            Server.MapPath("~/Upload/"),
                                            Path.GetFileNameWithoutExtension(FileUploadIndex.FileName) + "-" + id + "." + Path.GetExtension(FileUploadIndex.FileName)
                                        }
                                    )
                                )
                            );
                            Response.Redirect(
                                "ManualInvoice.aspx?" +
                                    "documentId=" + id + "&" +
                                    "enterpriseIndex=" + Request.QueryString["enterpriseIndex"] + "&" +
                                    "customerId=" + Request.QueryString["customerId"] + "&" +
                                    "customerName=" + Request.QueryString["customerName"] + "&" +
                                    "companyId=" + Request.QueryString["companyId"] + "&" +
                                    "companyName=" + Request.QueryString["companyName"] + "&" +
                                    "propertyId=" + Request.QueryString["propertyId"] + "&" +
                                    "propertyName=" + Request.QueryString["propertyName"]

                            );
                        }
                        else
                        {
                            labelErrorNoIndex.Visible = true;
                            labelErrorNoIndex.ForeColor = System.Drawing.Color.Red;
                            labelErrorNoIndex.Text = "File must be 1 meg(s) or smaller.";
                        }
                    }
                    else
                    {
                        labelErrorNoIndex.Visible = true;
                        labelErrorNoIndex.ForeColor = System.Drawing.Color.Red;
                        labelErrorNoIndex.Text = "File must be a pdf.";
                    }
                }
            }
            else
            {
                labelErrorNoIndex.Visible = true;
                labelErrorNoIndex.ForeColor = System.Drawing.Color.Red;
                labelErrorNoIndex.Text = "Please select a file.";
            }

        }

        protected void postIndex_Click(object sender, EventArgs e)
        {
            if (FileUploadIndex.HasFiles)
            {
                String fileExtension = System.IO.Path.GetExtension(FileUploadIndex.FileName).ToLower();
                String[] allowedExtensions = { ".pdf" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        string id = Guid.NewGuid().ToString();
                        if (FileUploadIndex.PostedFile.ContentLength < 1024000)
                        {
                            //FileUploadIndex.SaveAs(Path.Combine(Server.MapPath("~/Upload/"), id + "." + FileUploadIndex.FileName));
                            FileUploadIndex.SaveAs(
                                Path.Combine(
                                    new string[] {
                                        Server.MapPath("~/Upload/"),
                                        Path.GetFileNameWithoutExtension(FileUploadIndex.FileName) + "-" + id + "." + Path.GetExtension(FileUploadIndex.FileName)
                                    }
                                )
                            );
                            labelErrorIndex.Visible = true;
                            labelErrorIndex.ForeColor = System.Drawing.Color.Green;
                            labelErrorIndex.Text = "File Uploaded.";
                            /*
                            this.addDocument(
                                new FileInfo(
                                    Path.Combine(
                                        Server.MapPath("~/Upload/"), 
                                        id + "." + FileUploadIndex.FileName
                                    )
                                )
                            );
                            */
                            this.addDocument(
                                new FileInfo(
                                    Path.Combine(
                                        new string[] {
                                            Server.MapPath("~/Upload/"),
                                            Path.GetFileNameWithoutExtension(FileUploadIndex.FileName) + "-" + id + "." + Path.GetExtension(FileUploadIndex.FileName)
                                        }
                                    )
                                )
                            );
                        }
                        else
                        {
                            labelErrorIndex.Visible = true;
                            labelErrorIndex.ForeColor = System.Drawing.Color.Red;
                            labelErrorIndex.Text = "File must be 1 meg(s) or smaller.";
                        }
                    }
                    else
                    {
                        labelErrorIndex.Visible = true;
                        labelErrorIndex.ForeColor = System.Drawing.Color.Red;
                        labelErrorIndex.Text = "File must be a pdf.";
                    }
                }
            }
            else
            {
                labelErrorIndex.Visible = true;
                labelErrorIndex.ForeColor = System.Drawing.Color.Red;
                labelErrorIndex.Text = "Please select a file.";
            }
        }

        private void addDocument(FileInfo uploadFile)
        {

            var customer = this.User.Customers[EnterpriseIndex];

            ServiceConnection userServiceConnection = ServiceConnection.Create(
                new Uri(
                    String.Format(
                        "{0}://{1}/docuware/platform",
                        new object[] {
                            ConfigurationManager.AppSettings["DOCUWARE_SERVER_PROTOCOL"].ToString(),
                            ConfigurationManager.AppSettings["DOCUWARE_SERVER"].ToString()
                        }
                    )
                ),
                User.UserName.UserName,
                ConfigurationManager.AppSettings["DOCUWARE_GLOBAL_USERPASS"].ToString()
            );

            User user = (
                from
                    u in userServiceConnection.Organizations[0].GetUsersFromUsersRelation().User
                where
                    u.Name.ToUpper().Trim() == User.UserName.UserName.ToUpper().Trim()
                select u
            ).SingleOrDefault<User>();

            user.DefaultWebBasket = customer.Cabinet;


            FileCabinet fileCabinet = user.GetFileCabinetFromDefaultWebBasketRelation();

            var indexData = new Document()
            {
                Fields = new List<DocumentIndexField>()
                {
                    DocumentIndexField.Create("CUSTOMER_ID", (Request.QueryString["customerId"] == null) ? null : Request.QueryString["customerId"].ToString()),
                    DocumentIndexField.Create("COMPANYID", (Request.QueryString["companyId"] == null) ? null : Request.QueryString["companyId"].ToString()),
                    DocumentIndexField.Create("PROPERTYID", (Request.QueryString["propertyId"] == null) ? null : Request.QueryString["propertyId"].ToString()),
                    DocumentIndexField.Create("CREDS", Encrypt.EncryptString(this.User.Credentials.ToJsonString(),ConfigurationManager.AppSettings["BBDS_ENCRYPT_PASSWORD"].ToString()))
                }
            };
            fileCabinet.UploadDocument(indexData, uploadFile);
        }


        protected void btnGoToDocumentTray_Click(object sender, EventArgs e)
        {
            DWIntegrationInfo integrationInfo = new DWIntegrationInfo(
               String.Format(
                   "{0}://{1}/DocuWare/Platform/WebClient",
                   new object[] {
                       ConfigurationManager.AppSettings["DOCUWARE_IMGSERVER_PROTOCOL"].ToString(),
                       ConfigurationManager.AppSettings["DOCUWARE_IMGSERVER"].ToString(),
                   }
                ),
                1,
                false
            );
            integrationInfo.Scheme = ConfigurationManager.AppSettings["DOCUWARE_IMGSERVER_PROTOCOL"].ToString();
            integrationInfo.OrganizationId = "1";


            DWWebUrlLoginParameters loginParams = new DWWebUrlLoginParameters();


            loginParams.UserCredentials = new UserCredentials(
                ConfigurationManager.AppSettings["DOCUWARE_GLOBAL_USERPASS"].ToString(),
                User.UserName.UserName
            );

            DWWebClientLoginUrlEncrypted loginUrl = new DWWebClientLoginUrlEncrypted(integrationInfo, loginParams, ConfigurationManager.AppSettings["DOCUWARE_INTEGRATION_PASSPHRASE"].ToString());

            Response.Redirect(
                loginUrl.Url.ToString(),
                true
            );
        }


        protected void btnGoToWorkflow_Click(object sender, EventArgs e)
        {
            DWIntegrationInfo integrationInfo = new DWIntegrationInfo(
               String.Format(
                   "{0}://{1}/DocuWare/Platform/WebClient",
                   new object[] {
                       ConfigurationManager.AppSettings["DOCUWARE_IMGSERVER_PROTOCOL"].ToString(),
                       ConfigurationManager.AppSettings["DOCUWARE_IMGSERVER"].ToString(),
                   }
                ),
                1,
                false
            );
            integrationInfo.Scheme = ConfigurationManager.AppSettings["DOCUWARE_IMGSERVER_PROTOCOL"].ToString();
            integrationInfo.OrganizationId = "1";

            DWWebUrlLoginParameters loginParams = new DWWebUrlLoginParameters();
            loginParams.UserCredentials = new UserCredentials(
                ConfigurationManager.AppSettings["DOCUWARE_GLOBAL_USERPASS"].ToString(),
                User.UserName.UserName
            );

            DWWebClientLoginUrlEncrypted loginUrl = new DWWebClientLoginUrlEncrypted(integrationInfo, loginParams, ConfigurationManager.AppSettings["DOCUWARE_INTEGRATION_PASSPHRASE"].ToString());

            Response.Redirect(
                loginUrl.Url.ToString(),
                true
            );

        }

        protected void linkButtonLogout_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Session.Abandon();
            Response.Redirect(
                "Login.aspx"
            );
        }

        protected void btnUploadGoToTray_Click(object sender, EventArgs e)
        {
            int fileCount;
            if(Int32.TryParse(Session["FileUploadCount"].ToString(),out fileCount))
            {
                for(int i = 0; i != fileCount; i++)
                {
                    string fileName = Session["FileUploadName_" + i.ToString("000")].ToString();
                    Session["FileUploadName_" + i.ToString("000")] = null;
                    FileInfo fi = new FileInfo(fileName);
                    if (fi.Exists)
                    {
                        addDocument(fi);
                    }                    
                }
            }
            btnGoToDocumentTray_Click(sender, e);
            /*
            string fileName = Session["FileUploadName"].ToString();
            Session["FileUploadName"] = null;
            FileInfo fi = new FileInfo(fileName);
            if (fi.Exists)
            {
                addDocument(fi);
            }
            btnGoToDocumentTray_Click(sender, e);
            */
        }
    }
}

Commits for ChrisCompleteCodeTrunk/M3Workflow/M3Workflow.Web/Default.aspx.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000