示例#1
0
        public static void Main()
        {
            northwindData = new NorthwindDataSet();
            pendingOrdersData = new NorthwindDataSet();
            appSettingsData = new AppSettingsDataSet();
            orderData = new OrderApplicationDataClass();
            mainPOForm = new MainForm();
            mainPOForm.ShipViaListBox.SelectedIndex=0;
            try
            {
                //appSettingsData.ReadXml(Application.CommonAppDataPath + "\\AppSettings.xml");
                appSettingsData.ReadXml(".\\AppSettings.xml");
                employeeID = (int)appSettingsData.AppSettings[0].EmployeeID;
                empName = appSettingsData.AppSettings[0].EmployeeName;
                soundOn = appSettingsData.AppSettings[0].SoundOn;
            }
            catch
            {}

            try
            {
                //pendingOrdersData.ReadXml(Application.CommonAppDataPath + "\\PendingOrders.xml");
                pendingOrdersData.ReadXml(".\\PendingOrders.xml");
            }
            catch
            {}

            try
            {
                //northwindData.ReadXml(Application.CommonAppDataPath + "\\NorthwindData.xml");
                northwindData.ReadXml(".\\NorthwindData.xml");
                mainPOForm.BindControls();
                mainPOForm.ViewSubmittedOrdersMenuItem.Enabled = true;
                mainPOForm.NewOrderItemButton.Enabled = true;

            }
            catch
            {
                MessageBox.Show("The NorthwindData.xml file is missing or corrupt. Please connect to the database " +
                    "and rebuild this file using the Refresh Data option.", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            mainPOForm.UpdateStatusBar();
            Application.Run(mainPOForm);
        }
        public void RefreshLocalData()
        {
            NorthwindDataSet tempDataSet = new NorthwindDataSet();
            //if theMainModule.employeeID value is not set, call the ChooseEmployee method to
            //allow the user to choose their name from a list
            if (MainModule.employeeID == 0)
            {
                ChooseEmployee();
            }
            //try to open a connection
            if (NorthwindConnection.State != ConnectionState.Open)
            {
                try
                {
                    NorthwindConnection.Open();
                }
                catch (Exception Xcp)
                {
                    MessageBox.Show("Failed to connect because:\n" + Xcp.ToString() +"\n\nTry a different server name.", "Get from central database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            try
            {
                if (MainModule.employeeID > 0)
                {
                    //fill the temporary dataset
                    CustomersDataAdapter.Fill(tempDataSet.Customers);
                    ProductsDataAdapter.Fill(tempDataSet.Products);
                    OrdersDataAdapter.SelectCommand.Parameters["@EmployeeID"].Value =MainModule.employeeID;
                    OrdersDataAdapter.Fill(tempDataSet.Orders);
                    OrderDetailsDataAdapter.SelectCommand.Parameters["@EmployeeID"].Value =MainModule.employeeID;
                    OrderDetailsDataAdapter.Fill(tempDataSet.OrderDetails);

                    NorthwindConnection.Close();
                    //merge the temporary dataset into the nothwindData dataset and persist it
                    //as NorthwindData.xml in the CommonAppDataPath
                    MainModule.northwindData.Merge(tempDataSet, false);
                    MainModule.northwindData.AcceptChanges();
                    //MainModule.northwindData.WriteXml(Application.CommonAppDataPath + "\\NorthwindData.xml");
                    MainModule.northwindData.WriteXml(".\\NorthwindData.xml");
                }
                else
                {
                    return;
                }
            }
            catch(Exception Xcp)
            {
                MessageBox.Show(Xcp.ToString(), "Title", MessageBoxButtons.OK);
            }
            MainModule.mainPOForm.NewOrderItemButton.Enabled = true;
        }
        public void RefreshLocalData()
        {
            //TODO 1: Create a local instance of the NorthwindDataSet and name it tempDataSet.
            NorthwindDataSet tempDataSet = new NorthwindDataSet();

            //if theMainModule.employeeID value is not set, call the ChooseEmployee method to
            //allow the user to choose their name from a list
            if (MainModule.employeeID == 0)
            {
                ChooseEmployee();
            }
            //try to open a connection
            if (NorthwindConnection.State != ConnectionState.Open)
            {
                try
                {
                    NorthwindConnection.Open();
                }
                catch (Exception Xcp)
                {
                    MessageBox.Show("Failed to connect because:\n" + Xcp.ToString() +"\n\nTry a different server name.", "Get from central database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            try
            {
                if (MainModule.employeeID > 0)
                {
                    //fill the temporary dataset
                    CustomersDataAdapter.Fill(tempDataSet.Customers);
                    ProductsDataAdapter.Fill(tempDataSet.Products);

                    //TODO 2: Assign the @EmployeeID paramter for the OrdersDataAdapter Select Command to the global employee
                    OrdersDataAdapter.SelectCommand.Parameters["@employeeID"].Value = MainModule.employeeID;
                    OrderDetailsDataAdapter.SelectCommand.Parameters["@employeeID"].Value = MainModule.employeeID;

                    //TODO 3: Call the Fill method of OrdersDataAdapter
                    //to fill the Orders tables of the DataSet declared in TODO 1.
                    OrdersDataAdapter.Fill(tempDataSet);
                    OrderDetailsDataAdapter.Fill(tempDataSet);

                    NorthwindConnection.Close();
                    //merge the temporary dataset into the nothwindData dataset and persist it
                    //as NorthwindData.xml in the CommonAppDataPath
                    MainModule.northwindData.Merge(tempDataSet, false);
                    MainModule.northwindData.AcceptChanges();

                    //You can access this path by using Application.CommonAppDataPath.
                    //Concatenate the string returned by the CommonAppDataPath property with the name of the XML file, NorthwindData.XML
                    //MainModule.northwindData.WriteXml(Application.CommonAppDataPath + "\\NorthwindData.xml");
                    MainModule.northwindData.WriteXml(".\\NorthwindData.xml");
                }
                else
                {
                    return;
                }
            }
            catch(Exception Xcp)
            {
                MessageBox.Show(Xcp.ToString(), "Title", MessageBoxButtons.OK);
            }
            MainModule.mainPOForm.NewOrderItemButton.Enabled = true;
        }