Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     try
     {
         //Initialization
         DocumentDB documentDB = new DocumentDB
         {
             AuthorizationKey = "h6H3BgbraykUTr2yP3UEzgqXRqkaiixaliJI9UFgGEOU5JazdciFehayZgrJERwXQHwHOknVaH6FGygXBNVCeA==",
             EndpointUrl      = "https://abasu1.documents.azure.com:443/"
         };
         DocumentClient       client       = new DocumentClient(new Uri(documentDB.EndpointUrl), documentDB.AuthorizationKey);
         DocumentDBOperations dbOperations = new DocumentDBOperations(documentDB.EndpointUrl, documentDB.AuthorizationKey, client);
         Program p = new Program();
         //p.CreateDB(dbOperations).Wait();
         p.CreateCollections(dbOperations).Wait();
         p.CreateDocuments(dbOperations).Wait();
     }
     catch (DocumentClientException de)
     {
         Exception baseException = de.GetBaseException();
         Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
     }
     catch (Exception e)
     {
         Exception baseException = e.GetBaseException();
         Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
     }
     finally
     {
         Console.WriteLine("End of demo, press any key to exit.");
         Console.ReadKey();
     }
 }
Ejemplo n.º 2
0
 public RevitFamily Find(int id)
 {
     if (!this.Items.ContainsKey(id))
     {
         this.Items[id] = DocumentDB.GetElementById(id);
     }
     return(this.Items[id]);
 }
Ejemplo n.º 3
0
 private void initVariables()
 {
     clearData();
     docID = Main.currentDocument;
     pnlUI.Controls.Add(pnlList);
     DocumentDB.fillDocumentIDCumbo(cmbSelectDocument);
     btnNew.Visible = false;
     disableButtons();
 }
Ejemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                document   doc   = new document();
                DocumentDB docDB = new DocumentDB();
                doc.DocumentID     = txtDocumentID.Text;
                doc.DocumentName   = txtDocumentName.Text;
                doc.TableName      = txtTableName.Text;
                doc.IsReversible   = docDB.getYesNoCode(cmbIsReversible.SelectedItem.ToString());
                doc.DocumentStatus = docDB.getDocumentStatusCode(cmbDocumentStatus.SelectedItem.ToString());
                System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button;
                string btnText = btn.Text;

                {
                    if (btnText.Equals("Update"))
                    {
                        if (docDB.updateDocument(doc))
                        {
                            MessageBox.Show("Document Status updated");
                            closeAllPanels();
                            ListDocument();
                        }
                        else
                        {
                            MessageBox.Show("Failed to update Document Status");
                        }
                    }
                    else if (btnText.Equals("Save"))
                    {
                        if (docDB.validateDocument(doc))
                        {
                            if (docDB.insertDocument(doc))
                            {
                                MessageBox.Show("Document data Added");
                                closeAllPanels();
                                ListDocument();
                            }
                            else
                            {
                                MessageBox.Show("Failed to Insert Document");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Document Data Validation failed");
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Failed Adding / Editing User Data");
            }
        }
        private static async Task EnsureClientIsConnected()
        {
            if (client == null)
            {
                var connectionString = WebConfigurationManager.AppSettings["connectionString"];
                var databaseName     = WebConfigurationManager.AppSettings["databaseName"];
                var collectionName   = WebConfigurationManager.AppSettings["collectionName"];

                collectionLink     = string.Format("dbs/{0}/colls/{1}", databaseName, collectionName);
                documentLinkFormat = collectionLink + "/docs/{0}";

                client = await DocumentDB.GetDocumentClient(connectionString, databaseName, collectionName);
            }
        }
        /// <summary>
        /// The DeleteBtn_Click event handler on this Page is used to delete an
        /// a document. It uses the Rainbow.DocumentsDB()
        /// data component to encapsulate all data functionality.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected override void OnDelete(EventArgs e)
        {
            base.OnDelete(e);

            // Only attempt to delete the item if it is an existing item
            // (new items will have "ItemID" of 0)
            //TODO: Ask confim before delete
            if (ItemID != 0)
            {
                DocumentDB documents = new DocumentDB();
                documents.DeleteDocument(ItemID, Server.MapPath(PathField.Text));
            }
            RedirectBackToReferringPage();
        }
Ejemplo n.º 7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                document   doc   = new document();
                DocumentDB docDB = new DocumentDB();
                System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button;
                string btnText = btn.Text;

                {
                    if (btnText.Equals("Update"))
                    {
                        if (docDB.updateDocument(doc))
                        {
                            MessageBox.Show("Document Status updated");
                            closeAllPanels();
                            //ListDocument();
                        }
                        else
                        {
                            MessageBox.Show("Failed to update Document Status");
                        }
                    }
                    else if (btnText.Equals("Save"))
                    {
                        if (docDB.validateDocument(doc))
                        {
                            if (docDB.insertDocument(doc))
                            {
                                MessageBox.Show("Document data Added");
                                closeAllPanels();
                                //ListDocument();
                            }
                            else
                            {
                                MessageBox.Show("Failed to Insert Document");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Document Data Validation failed");
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Failed Adding / Editing User Data");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// The Page_Load event handler on this Page is used to
        /// obtain obtain the contents of a document from the
        /// Documents table, construct an HTTP Response of the
        /// correct type for the document, and then stream the
        /// document contents to the response.  It uses the
        /// Rainbow.DocumentDB() data component to encapsulate
        /// the data access functionality.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            if (ItemID != -1)
            {
                // Obtain Document Data from Documents table
                DocumentDB documents = new DocumentDB();

                // Change by [email protected]
                // Date: 7/2/2003
                WorkFlowVersion version = Request.QueryString["wversion"] == "Staging"
                                              ? WorkFlowVersion.Staging
                                              : WorkFlowVersion.Production;
                // End Change [email protected]

                // Change by [email protected]
                // Date: 7/2/2003
                // Original:
                // SqlDataReader dBContent = documents.GetDocumentContent(ItemID);
                SqlDataReader dBContent = documents.GetDocumentContent(ItemID, version);
                // End Change [email protected]

                try
                {
                    dBContent.Read();

                    // Serve up the file by name
                    // [email protected]. FIX: FileName does not exist
                    // Response.AppendHeader("content-disposition", "filename=" + (string)dBContent["FileName"]);
                    Response.AppendHeader("content-disposition", "filename=" + (string)dBContent["FileNameUrl"]);

                    // set the content type for the Response to that of the
                    // document to display.  For example. "application/msword"
                    // Change for translate extension-files to exact contentType
                    // Response.ContentType = (string) dBContent["ContentType"];
                    Response.ContentType = giveMeContentType((string)dBContent["ContentType"]);

                    // output the actual document contents to the response output stream
                    Response.OutputStream.Write((byte[])dBContent["Content"], 0, (int)dBContent["ContentSize"]);
                }
                finally
                {
                    dBContent.Close(); //by Manu, fixed bug 807858
                }

                // end the response
                Response.End();
            }
        }
        public void CanRetrieveNullCollectionProperty()
        {
            /* todo: The service can return a null collection, but apparently the client needs that feature added as well
             *       I suppose it's not that big a deal though, since you have control over the object at this point
             * var create = House.CreateHouse(Guid.NewGuid().ToString("D"));
             * create.TestWindows = null;
             * client.AddToHouses(create);
             * client.SaveChanges();
             * client.Detach(create);*/

            // because of the above bug, we must create the document directly, but this is the more important path anyway
            var connectionString   = ConfigurationManager.AppSettings["connectionString"];
            var databaseName       = ConfigurationManager.AppSettings["databaseName"];
            var collectionName     = ConfigurationManager.AppSettings["collectionName"];
            var collectionLink     = string.Format("dbs/{0}/colls/{1}", databaseName, collectionName);
            var documentLinkFormat = collectionLink + "/docs/{0}";
            var task = DocumentDB.GetDocumentClient(connectionString, databaseName, collectionName);

            task.Wait();
            var docClient = task.Result;

            // make test document
            HouseDocument houseDocument = new HouseDocument();

            houseDocument.Id          = Guid.NewGuid().ToString("D");
            houseDocument.TestWindows = null;

            // insert it directly to DocumentDB
            DocumentDbExtensions.ExecuteResultWithRetry(() =>
                                                        docClient.UpsertDocumentAsync(collectionLink, houseDocument));

            // retrieve it directly from DocumentDB
            var retrievedDocument = DocumentDbExtensions.ExecuteQueryWithContinuationAndRetry(
                docClient.CreateDocumentQuery <HouseDocument>(collectionLink)
                .Where(x => x.Id == houseDocument.Id))
                                    .Single();

            // is the test set up properly?
            Assert.IsNull(retrievedDocument.TestWindows);

            // finally, test retrieval through OData
            var house = odataClient.Houses.ByKey(houseDocument.Id).GetValue();

            Assert.IsNotNull(house);
            // note: house.TestWindows will actually be deserialized as an empty collection here, but the test is
            //       that the OData service didn't throw an error when encountering that in the source document
        }
        /// <summary>
        /// The Page_Load event on this Page is used to obtain the ModuleID
        /// and ItemID of the document to edit.
        /// It then uses the DocumentDB() data component
        /// to populate the page's edit controls with the document details.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            // If the page is being requested the first time, determine if an
            // document itemID value is specified, and if so populate page
            // contents with the document details

            if (!Page.IsPostBack)
            {
                if (ModuleID > 0)
                {
                    PathToSave = ((SettingItem)moduleSettings["DocumentPath"]).FullPath;
                }

                if (ItemID > 0)
                {
                    // Obtain a single row of document information
                    DocumentDB    documents = new DocumentDB();
                    SqlDataReader dr        = documents.GetSingleDocument(ItemID, WorkFlowVersion.Staging);

                    try
                    {
                        // Load first row into Datareader
                        if (dr.Read())
                        {
                            NameField.Text     = (string)dr["FileFriendlyName"];
                            PathField.Text     = (string)dr["FileNameUrl"];
                            CategoryField.Text = (string)dr["Category"];
                            CreatedBy.Text     = (string)dr["CreatedByUser"];
                            CreatedDate.Text   = ((DateTime)dr["CreatedDate"]).ToShortDateString();
                            // 15/7/2004 added localization by Mario Endara [email protected]
                            if (CreatedBy.Text == "unknown")
                            {
                                CreatedBy.Text = General.GetString("UNKNOWN", "unknown");
                            }
                        }
                    }
                    finally
                    {
                        dr.Close();
                    }
                }
            }
        }
Ejemplo n.º 11
0
 private void ListDocument()
 {
     try
     {
         grdList.Rows.Clear();
         DocumentDB      dbrecord  = new DocumentDB();
         List <document> Documents = dbrecord.getDocuments();
         foreach (document doc in Documents)
         {
             grdList.Rows.Add(doc.DocumentID, doc.DocumentName, doc.TableName,
                              dbrecord.getYesNo(doc.IsReversible),
                              dbrecord.getDocumentStatusString(doc.DocumentStatus));
             //dbrecord.getEmpStatusString(emp.empStatus), emp.empPhoto);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error");
     }
     enableBottomButtons();
     pnlDocumentList.Visible = true;
 }
Ejemplo n.º 12
0
        private void LoadData(int?intKeyUte)
        {
            user = UsersDB.LoadUser(intKeyUte).First();

            if (user == null)
            {
                return;
            }

            txtNome.Text          = user.NOME;
            txtCognome.Text       = user.COGNOME;
            cmbSst.SelectedItem   = user.SST;
            txtStrada.Text        = user.STRADA;
            dateTimePicker1.Value = user.DTNAS;

            if (user.KEY_NAZ != null)
            {
                cmbNaz.SelectedValue = user.KEY_NAZ;
            }

            if (user.KEY_REG != null)
            {
                cmbReg.SelectedValue = user.KEY_REG;
            }

            if (user.KEY_PRO != null)
            {
                cmbProv.SelectedValue = user.KEY_PRO;
            }

            if (user.KEY_COM != null)
            {
                cmbCom.SelectedValue = user.KEY_COM;
            }

            if (user.KEY_LOC != null)
            {
                cmbLoc.SelectedValue = user.KEY_LOC;
            }

            if (user.TYP_UTE != null)
            {
                cmbTYP_UTE.SelectedIndex = int.Parse(user.TYP_UTE);
            }

            if (user.SEX != null)
            {
                cmbSEX.SelectedValue = user.SEX;
            }

            txtCF.Text   = user.COD_FIS;
            txtPiva.Text = user.P_IVA;
            txtNcn.Text  = user.NCN;
            txtCell.Text = user.CELL;
            txtTel.Text  = user.TEL;
            txtMail.Text = user.MAIL;

            if ((cmbTemplate.SelectedIndex != -1) && (cmbTemplate.SelectedItem != null) && (cmbTemplate.Items.Count > 1))
            {
                cmbTemplate.SelectedIndex = user.KEY_TEMPL;
            }

            if (user.KEY_NAZ_NAS != null)
            {
                cmbNazNas.SelectedValue = user.KEY_NAZ_NAS;
            }

            if (user.KEY_REG_NAS != null)
            {
                cmbRegNas.SelectedValue = user.KEY_REG_NAS;
            }

            if (user.KEY_PRO_NAS != null)
            {
                cmbProvNas.SelectedValue = user.KEY_PRO_NAS;
            }

            if (user.KEY_COM_NAS != null)
            {
                cmbComNas.SelectedValue = user.KEY_COM_NAS;
            }

            if (user.KEY_LOC_NAS != null)
            {
                cmbLocNas.SelectedValue = user.KEY_LOC_NAS;
            }

            if (user.KEY_DOC.HasValue)
            {
                intKeyDoc = user.KEY_DOC;
            }

            document = DocumentDB.LoadDocument(user.KEY_DOC);
            if (document != null)
            {
                if (document.TYP_DOC.HasValue)
                {
                    cmbTyp_DOC.SelectedIndex = document.TYP_DOC.GetValueOrDefault();
                }

                txtIdDoc.Text = document.ID_DOC;
                if (DateTime.MinValue < document.ISS_DOC && document.ISS_DOC < DateTime.MaxValue)
                {
                    dtmPickDocument.Value = document.ISS_DOC;
                }

                txtCityDoc.Text = document.CITY_DOC;
                txtNumber.Text  = document.NUM_DOC;
            }

            TemplateLinq template = new TemplateLinq();

            template.KEY_USER    = user.KEY_USER;
            template.KEY_TEMPL_L = user.KEY_TEMPL;

            LoadTemplate_Linq(template);
            bFreeze = false;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Called during startup by each shared project
        /// </summary>
        public static void Initialize(string environment)
        {
            //Initialize all static settings classes based on current environment
            //See "instructions.txt" for details  on the configurations to use per environment.
            //Host application must pass in the current environment name to initialize settings


            Environment.Current = environment;



            //---------------------------------------------------------------------

            //URLs & Email Addresses are initialized first as they are used in copy within other settings

            // Endpoint Settings ---------------
            URLs.Initialize();
            Emails.Initialize();


            //---------------------------------------------------------------------

            // Remaining settings are then initialized...

            // AZURE Services -----------------
            Databases.Initialize();
            DocumentDB.Initialize();
            Redis.Initialize();
            Storage.Initialize();
            Search.Initialize();

            // EXTERNAL Services ---------------
            Stripe.Initialize();
            SendGrid.Initialize();
            MailChimp.Initialize();
            GoogleMaps.Initialize();
            CloudFlare.Initialize();

            Registration.Initialize();
            GarbageCollection.Initialize();
            Custodian.Initialize();
            Worker.Initialize();
            Partitioning.Initialize();
            Payments.Initialize();

            // Platform Settings ---------------
            Application.Initialize();
            Platform.Users.Initialize();
            Accounts.Users.Initialize();
            Commerce.Credits.Initialize();

            //Copy Settings ---------------
            EmailMessages.Initialize();
            NotificationMessages.Initialize();
            PlatformMessages.Initialize();

            //Image Settings ------------
            Imaging.Images.Initialize();


            // Flush ALL Redis caches when we initialize CoreServices
            // This allows new updates to be forced into cached objects
            var redisEndpoints = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetEndPoints(true);
            var redisserver    = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetServer(redisEndpoints[0]);

            try
            {
                redisserver.FlushAllDatabases();
            }
            catch (Exception e)
            {
                string exception = e.Message;
            }


            /*
             * // Flush ALL Redis caches when we initialize CoreServices
             * // This allows new updates to be forced into cached objects
             * var accountsRedisEndpoints = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetEndPoints(true);
             * var accountRedisserver = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetServer(accountsRedisEndpoints[0]);
             * accountRedisserver.FlushAllDatabases();
             *
             * var platformRedisEndpoints = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.PlatformManager_Multiplexer.GetEndPoints(true);
             * var platformRedisserver = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.PlatformManager_Multiplexer.GetServer(platformRedisEndpoints[0]);
             * platformRedisserver.FlushAllDatabases();
             */
        }
        protected override void OnUpdate(EventArgs e)
        {
            base.OnUpdate(e);
            byte[] buffer = new byte[0];
            int    size   = 0;

            // Only Update if Input Data is Valid
            if (Page.IsValid)
            {
                // Create an instance of the Document DB component
                DocumentDB documents = new DocumentDB();

                // Determine whether a file was uploaded
                if (FileUpload.PostedFile.FileName != string.Empty)
                {
                    FileInfo fInfo = new FileInfo(FileUpload.PostedFile.FileName);
                    if (bool.Parse(moduleSettings["DOCUMENTS_DBSAVE"].ToString()))
                    {
                        Stream stream = FileUpload.PostedFile.InputStream;
                        buffer = new byte[FileUpload.PostedFile.ContentLength];
                        size   = FileUpload.PostedFile.ContentLength;
                        try
                        {
                            stream.Read(buffer, 0, size);
                            PathField.Text = fInfo.Name;
                        }
                        finally
                        {
                            stream.Close(); //by manu
                        }
                    }
                    else
                    {
                        PathToSave = ((SettingItem)moduleSettings["DocumentPath"]).FullPath;
                        // [email protected] (02/07/2004). Create the Directory if not exists.
                        if (!Directory.Exists(Server.MapPath(PathToSave)))
                        {
                            Directory.CreateDirectory(Server.MapPath(PathToSave));
                        }

                        string virtualPath  = Path.WebPathCombine(PathToSave, fInfo.Name);
                        string physicalPath = Server.MapPath(virtualPath);

//						while(System.IO.File.Exists(physicalPath))
//						{
//							// Calculate virtualPath of the newly uploaded file
//							virtualPath = Rainbow.Framework.Settings.Path.WebPathCombine(PathToSave, Guid.NewGuid().ToString() + fInfo.Extension);
//
//							// Calculate physical path of the newly uploaded file
//							phyiscalPath = Server.MapPath(virtualPath);
//						}
                        while (File.Exists(physicalPath))
                        {
                            try
                            {
                                // Delete file before upload
                                File.Delete(physicalPath);
                            }
                            catch (Exception ex)
                            {
                                Message.Text =
                                    General.GetString("ERROR_FILE_DELETE", "Error while deleting file!<br>") +
                                    ex.Message;
                                return;
                            }
                        }

                        try
                        {
                            // Save file to uploads directory
                            FileUpload.PostedFile.SaveAs(physicalPath);

                            // Update PathFile with uploaded virtual file location
                            PathField.Text = virtualPath;
                        }
                        catch (Exception ex)
                        {
                            Message.Text = General.GetString("ERROR_FILE_NAME", "Invalid file name!<br>") + ex.Message;
                            return;
                        }
                    }
                }
                // Change for save contenType and document buffer
                // documents.UpdateDocument(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, NameField.Text, PathField.Text, CategoryField.Text, new byte[0], 0, string.Empty );
                string contentType = PathField.Text.Substring(PathField.Text.LastIndexOf(".") + 1).ToLower();
                documents.UpdateDocument(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, NameField.Text,
                                         PathField.Text, CategoryField.Text, buffer, size, contentType);

                RedirectBackToReferringPage();
            }
        }
Ejemplo n.º 15
0
 public data()
 {
     InitializeComponent();
     documentDB = new DocumentDB(dbName: Config.CurrentConfig.DocumentsDBName, ip: Config.CurrentConfig.DocumentsDBIp);
 }
        /// <summary>
        /// The Page_Load event handler on this User Control is used to
        /// obtain a SqlDataReader of document information from the
        /// Documents table, and then databind the results to a DataGrid
        /// server control.  It uses the Rainbow.DocumentDB()
        /// data component to encapsulate all data functionality.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            LoadAvailableImageList();

            if (!Page.IsPostBack)
            {
                string sortFieldOption     = Settings["DOCUMENTS_SORTBY_FIELD"].ToString();
                string sortDirectionOption = Settings["DOCUMENTS_SORTBY_DIRECTION"].ToString();
                if (sortFieldOption.Length > 0)
                {
                    if (General.GetString("DOCUMENTS_SORTBY_FIELD_LIST", "File Name;Created Date").IndexOf(sortFieldOption) > 0)
                    {
                        sortField = "CreatedDate";
                    }
                    else
                    {
                        sortField = "FileFriendlyName";
                    }

                    if (General.GetString("DOCUMENTS_SORTBY_DIRECTION_LIST", "Ascending;Descending").IndexOf(sortDirectionOption) > 0)
                    {
                        sortDirection = "DESC";
                    }
                    else
                    {
                        sortDirection = "ASC";
                    }
                }
                else
                {
                    sortField     = "FileFriendlyName";
                    sortDirection = "ASC";
                    if (sortField == "DueDate")
                    {
                        sortDirection = "DESC";
                    }
                }
                ViewState["SortField"]     = sortField;
                ViewState["SortDirection"] = sortDirection;
            }
            else
            {
                sortField     = (string)ViewState["SortField"];
                sortDirection = (string)ViewState["sortDirection"];
            }

            myDataView = new DataView();

            // Obtain Document Data from Documents table
            // and bind to the datalist control
            DocumentDB documents = new DocumentDB();

            // DataSet documentsData = documents.GetDocuments(ModuleID, Version);
            // myDataView = documentsData.Tables[0].DefaultView;
            setDataView(documents.GetDocuments(ModuleID, Version));

            if (!Page.IsPostBack)
            {
                myDataView.Sort = sortField + " " + sortDirection;
            }

            BindGrid();
        }
Ejemplo n.º 17
0
        public async Task <List <Document> > Get(string CustomerID)
        {
            var db = new DocumentDB(_storageConnectionString);

            return(await db.GetDocumentAsync(CustomerID));
        }
Ejemplo n.º 18
0
        internal void Save()
        {
            if (user == null)
            {
                user = new Users();
            }
            else
            {
                user.KEY_USER = intKeyUtenze.GetValueOrDefault();
            }

            user.NOME    = txtNome.Text;
            user.COGNOME = txtCognome.Text;
            user.DTINS   = DateTime.Now;
            user.DTNAS   = dateTimePicker1.Value.Date;

            if (cmbSst.SelectedItem != null)
            {
                if (!string.IsNullOrEmpty(cmbSst.SelectedItem.ToString()))
                {
                    user.SST = cmbSst.SelectedItem.ToString();
                }
            }
            user.STRADA  = txtStrada.Text;
            user.TYP_UTE = (cmbTYP_UTE.SelectedIndex).ToString();
            user.COD_FIS = txtCF.Text;
            user.P_IVA   = txtPiva.Text;
            user.NCN     = txtNcn.Text;
            user.CELL    = txtCell.Text;
            user.TEL     = txtTel.Text;
            user.MAIL    = txtMail.Text;

            if (cmbNaz.SelectedItem != null)
            {
                user.KEY_NAZ = Convert.ToInt32(((DataRowView)cmbNaz.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbReg.SelectedItem != null)
            {
                user.KEY_REG = Convert.ToInt32(((DataRowView)cmbReg.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbProv.SelectedItem != null)
            {
                user.KEY_PRO = Convert.ToInt32(((DataRowView)cmbProv.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbCom.SelectedItem != null)
            {
                user.KEY_COM = Convert.ToInt32(((DataRowView)cmbCom.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbLoc.SelectedItem != null)
            {
                user.KEY_LOC = Convert.ToInt32(((DataRowView)cmbLoc.SelectedItem).Row.ItemArray[0]);
            }


            if (cmbNazNas.SelectedItem != null)
            {
                user.KEY_NAZ_NAS = Convert.ToInt32(((DataRowView)cmbNazNas.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbRegNas.SelectedItem != null)
            {
                user.KEY_REG_NAS = Convert.ToInt32(((DataRowView)cmbRegNas.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbProvNas.SelectedItem != null)
            {
                user.KEY_PRO_NAS = Convert.ToInt32(((DataRowView)cmbProvNas.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbComNas.SelectedItem != null)
            {
                user.KEY_COM_NAS = Convert.ToInt32(((DataRowView)cmbComNas.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbLocNas.SelectedItem != null)
            {
                user.KEY_LOC_NAS = Convert.ToInt32(((DataRowView)cmbLocNas.SelectedItem).Row.ItemArray[0]);
            }

            if (cmbSEX.SelectedItem != null)
            {
                user.SEX = ((KeyValuePair <string, string>)cmbSEX.SelectedItem).Key;
            }

            user.KEY_TEMPL = cmbTemplate.SelectedIndex;

            if (document == null)
            {
                document = new Document();
            }
            else
            {
                document.KEY_DOC = intKeyDoc.GetValueOrDefault();
            }

            document.TYP_DOC = cmbTyp_DOC.SelectedIndex;
            document.NUM_DOC = txtNumber.Text;

            if (DateTime.MinValue < dtmPickDocument.Value.Date && dtmPickDocument.Value.Date < DateTime.MaxValue)
            {
                document.ISS_DOC = dtmPickDocument.Value.Date;
            }

            document.CITY_DOC = txtCityDoc.Text;
            document.ID_DOC   = txtIdDoc.Text;

            try
            {
                if (!GestioneMySql.OpenConnection())
                {
                    throw new Exception("Errore nell'apertura della connessione.");
                }

                DocumentDB.SaveDocument(document);
                user.KEY_DOC = document.KEY_DOC;
                UsersDB.SaveUser(user);

                if (!GestioneMySql.CloseConnection())
                {
                    throw new Exception("Errore nella chiusura della connessione.");
                }
            }
            catch (Exception ex)
            {
                GestioneMySql.CloseConnection();
                MessageBox.Show("Errore: " + ex.Message);
            }

            intKeyUtenze = user.KEY_USER;
        }