C#: Capture a ScreenShot

The following code demonstrates one method of capturing a screenshot. The method displayed returns a screenshot of the entire screen as a bitmap.

 

private Bitmap GetScreenShot()
        {
            // set screenshot bounds to match the size of the screen
            Rectangle bounds = Screen.PrimaryScreen.Bounds;
            // crate a bitmap with the dimensions of the sreen
            Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
            }
            return bitmap;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = GetScreenShot();
        }



   

Microsoft Dynamics Nav: Adding a Record through Web Services

Microsoft Dynamics Nav Web Services can not only read data, but they can also write data to a Microsoft Dynamics Nav database. This example demonstrates adding a record into a Microsoft Dynamics Nav database through Web Services using an XMLPort.

Microsoft Dynamics Nav: Adding a Record through Web Services

  1. Create and XMLPort for transferring the data. Note: For this example the MaxOccurs property of the element should be set to ‘One’ to set a “one record limit”. It is possible to set multiple records
  2. 1.Create and XMLPort for transferring the data.

  3. Create a CodeUnit and add functions that will be used to through the Web Service
  4. GetCustomers(CustomerCode : Code[10];VAR CustXML : XMLport GetSetCustomer) Customer.SETRANGE("No.", CustomerCode); CustXML.SETTABLEVIEW(Customer); SetCustomers(VAR CustXML : XMLport GetSetCustomer) : Integer // Return 1 if import was successful IF CustXML.IMPORT THEN  EXIT(1) ELSE  EXIT(0);

  5. Publish the CodeUnit as a Web Service
  6. 3.Publish the CodeUnit as a Web Service

  7. Create a .NET Application and register the Microsoft Dynamics Nav Web Service
  8. Create the code that interacts with the registered Web Service (Note: This code is for basic demonstration only and additional coding practices should be applied for production code)
    GetSetCustomers_Binding ws;
    
            private void Form1_Load(object sender, EventArgs e)
            {
                ws = new GetSetCustomers_Binding();
                ws.UseDefaultCredentials = true;
                ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS%20USA,%20Inc./Codeunit/GetSetCustomers";
    
            }
    
            private void btnGet_Click(object sender, EventArgs e)
            {
                Customer cust = new Customer();
                Customers cs = new Customers();
                // in nav the XML should be set to maxoccurence of 1 so that we only return one 
                //customer
                ws.GetCustomers(txtNo.Text, ref cs);
    
                cust = cs.Customer[0];
                txtName.Text = cust.Name;
                txtPhone.Text = cust.Phone_No_;
                txtContact.Text = cust.Contact;
            }
    
            private void btnSet_Click(object sender, EventArgs e)
            {
                Customers cs = new Customers();
                Customer cust = new Customer();
                List<Customer> custlist = new List<Customer>();
    
                cust.No_ = txtNo.Text;
                cust.Name = txtName.Text;
                cust.Phone_No_ = txtPhone.Text;
                cust.Contact = txtContact.Text;
                custlist.Add(cust);
                cs.Customer = custlist.ToArray();
    
                if (ws.SetCustomers(ref cs) == 0)
                {
                    MessageBox.Show("No Good.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                };
            }

The sample application referenced in this post can be downloaded >>>here<<<.

View the following posts for additional examples:

Microsoft Dynamics Nav: Retrieving a set of Records through Web Services

Microsoft Dynamics Nav: Using an XMLPort as a .NET DataSource



   

Microsoft Dynamics Nav: Retrieving a set of Records through Web Services

In a previous post ( Microsoft Dynamics Nav: Using an XMLPort as a .NET DataSource and Microsft Dynamics Nav: Export XMLPort to File) I had demonstrated how to return a set of records, using Web Services, from Microsoft Dynamics Nav with an XMLPort as a dataset.

Microsoft Dynamics Nav: Retrieving a set of Records through Web Services

The following example demonstrates returning a filtered set of records from Microsoft Dynamics Nav through Services. 

 
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        GetCustomers_Binding ws;
        Customers customers;
        BindingSource bs;

        private void Form1_Load(object sender, EventArgs e)
        {
            ws = new GetCustomers_Binding();
            ws.UseDefaultCredentials = true;
            ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS%20USA,%20Inc./Codeunit/GetCustomers";

            customers = new Customers();
            bs = new BindingSource();

            BindData(textBox1.Text);
        }

        private void BindData(string salespersoncode)
        {
            ws.GetCustomers(salespersoncode, ref customers);
            dataGridView1.DataSource = bs;
            bs.DataSource = customers.Customer;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BindData(textBox1.Text);
        }
    }

GetCustomers(SalesPerson : Code[10];VAR CustXML : XMLport Customer_Export) IF SalesPerson <> '' THEN Customer.SETRANGE("Salesperson Code",'PS'); CustXML.SETTABLEVIEW(Customer);

The sample application referenced in this post can be downloaded >>>here<<<.