コード例 #1
0
        private void btnSaveAgent_Click(object sender, RoutedEventArgs e)
        {
            try {
                Agent agent = new Agent();

                agent.Id          = int.Parse(txtAgentId.Text);
                agent.Name        = txtAgentName.Text;
                agent.Nationality = txtAgentNationality.Text;
                agent.CPR         = txtAgentCPR.Text;

                AgentWrapper.SaveAgent(agent);

                // Try to save appearance
                if (txtAgentHeight.Text != "" || txtAgentEyecolor.Text != "" || txtAgentHaircolor.Text != "")
                {
                    Appearance appearance;
                    if (agent.Id == -1)
                    {
                        appearance = new Appearance(int.Parse(txtAgentHeight.Text), txtAgentEyecolor.Text, txtAgentHaircolor.Text, InfoWrapper.GetLastPersonId());
                    }
                    else
                    {
                        appearance = new Appearance(int.Parse(txtAgentHeight.Text), txtAgentEyecolor.Text, txtAgentHaircolor.Text, agent.Id);
                    }

                    InfoWrapper.SaveAppearence(appearance);
                }

                // Try to save address
                if (txtAgentStreet.Text != "" || txtAgentAreacode.Text != "")
                {
                    Address address;
                    // Check if it's a new agent
                    if (agent.Id == -1)
                    {
                        address = new Address(txtAgentStreet.Text, int.Parse(txtAgentAreacode.Text), InfoWrapper.GetLastPersonId());
                    }
                    else
                    {
                        address = new Address(txtAgentStreet.Text, int.Parse(txtAgentAreacode.Text), agent.Id);
                    }

                    InfoWrapper.SaveAddress(address);
                }

                // Try to save image
                if (txtAgentImagePath.Text != "")
                {
                    if (File.Exists(txtAgentImagePath.Text))
                    {
                        FileStream   fs = new FileStream(txtAgentImagePath.Text, FileMode.Open, FileAccess.Read);
                        BinaryReader br = new BinaryReader(fs);

                        Database.Entities.Image img;

                        // if new agent
                        if (agent.Id == -1)
                        {
                            img = new Database.Entities.Image(br.ReadBytes(Convert.ToInt32(fs.Length)), InfoWrapper.GetLastPersonId());
                        }
                        else
                        {
                            img = new Database.Entities.Image(br.ReadBytes(Convert.ToInt32(fs.Length)), agent.Id);
                        }

                        InfoWrapper.SaveImage(img);
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show($"Der er sket en fejl. Er alle felterne korrekt udfyldt?\n\n{ex.Message}");
            }
        }
コード例 #2
0
        private void btnSaveInformer_Click(object sender, RoutedEventArgs e)
        {
            try {
                Informer informer = new Informer();

                informer.Id          = int.Parse(txtInformerId.Text);
                informer.Name        = txtInformerName.Text;
                informer.Nationality = txtInformerNationality.Text;
                informer.CPR         = txtInformerCPR.Text;
                informer.Currency    = txtInformerCurrency.Text;
                informer.PaymentType = txtInformerPaymentType.Text;
                informer.Tags        = txtInformerTags.Text;

                InformerWrapper.SaveInformer(informer);

                // Try to save appearance
                if (txtInformerHeight.Text != "" || txtInformerEyecolor.Text != "" || txtInformerHaircolor.Text != "")
                {
                    Appearance appearance;
                    if (informer.Id == -1)
                    {
                        appearance = new Appearance(int.Parse(txtInformerHeight.Text), txtInformerEyecolor.Text, txtInformerHaircolor.Text, InfoWrapper.GetLastPersonId());
                    }
                    else
                    {
                        appearance = new Appearance(int.Parse(txtInformerHeight.Text), txtInformerEyecolor.Text, txtInformerHaircolor.Text, informer.Id);
                    }

                    InfoWrapper.SaveAppearence(appearance);
                }

                // Try to save address
                if (txtInformerStreet.Text != "" || txtInformerAreacode.Text != "")
                {
                    Address address;
                    // If it's a new informer
                    if (informer.Id == -1)
                    {
                        address = new Address(txtInformerStreet.Text, int.Parse(txtInformerAreacode.Text), InfoWrapper.GetLastPersonId());
                    }
                    else
                    {
                        address = new Address(txtInformerStreet.Text, int.Parse(txtInformerAreacode.Text), informer.Id);
                    }

                    InfoWrapper.SaveAddress(address);
                }

                // Try to save image
                if (txtInformerImagePath.Text != "")
                {
                    if (File.Exists(txtInformerImagePath.Text))
                    {
                        FileStream   fs = new FileStream(txtInformerImagePath.Text, FileMode.Open, FileAccess.Read);
                        BinaryReader br = new BinaryReader(fs);

                        Database.Entities.Image img;

                        // if new informer
                        if (informer.Id == -1)
                        {
                            img = new Database.Entities.Image(br.ReadBytes(Convert.ToInt32(fs.Length)), InfoWrapper.GetLastPersonId());
                        }
                        else
                        {
                            img = new Database.Entities.Image(br.ReadBytes(Convert.ToInt32(fs.Length)), informer.Id);
                        }

                        InfoWrapper.SaveImage(img);
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show($"Der er sket en fejl. Er alle felterne korrekt udfyldt?\n\n{ex.Message}");
            }
        }