Esempio n. 1
0
 //加载数据
 private void LoadData()
 {
     try
     {
         SupplierAdapter adapter = new SupplierAdapter(SQLConnection.GetDataBase());
         Suppliers = adapter.GetAllSupplier();        //获取所有供应商信息
         LV_Supplier.ItemsSource = Suppliers.Tables[0].DefaultView;
     }
     catch (Exception ex)
     {
         MessageBox.Show("异常发生,请检查数据库连接", "错误", MessageBoxButton.OK,
                         MessageBoxImage.Error);
         //写入日志
     }
 }
        //加载数据
        private void LoadData()
        {
            try
            {
                DataSet         SupplierList;
                SupplierAdapter sadapter = new SupplierAdapter(
                    SQLConnection.GetDataBase());
                PurchaseAdapter padapter = new PurchaseAdapter(
                    SQLConnection.GetDataBase());

                SupplierList = sadapter.GetAllSupplier();           //获取所有供应商信息
                PurchaseList = padapter.GetAllPurchase();           //获取所有进货信息

                DataTable     table   = SupplierList.Tables["Supplier"];
                DataSetHelper phelper = new DataSetHelper(ref PurchaseList);

                SupplierList.Tables.Remove("Supplier");
                PurchaseList.Tables.Add(table);    //添加子表
                PurchaseList.Relations.Add("PAndS", PurchaseList.Tables["Supplier"].Columns["Sno"],
                                           PurchaseList.Tables["Purchase"].Columns["Sno"]);

                phelper.SelectJoinInto("PurchaseAndSupplier", PurchaseList.Tables["Purchase"],
                                       "Pno,Sno,PAndS.Sname,Pdate", "1=1", "Pno");

                //加载进货信息
                LV_PurchaseAndSupplier.ItemsSource = PurchaseList.Tables["PurchaseAndSupplier"].DefaultView;

                //加载进货细节
                if (LV_PurchaseAndSupplier.Items.Count != 0)
                {
                    //选择第一项
                    LV_PurchaseAndSupplier.SelectedIndex = 0;
                    LoadPurchaseDetailData(0);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常发生,请检查数据库连接", "错误", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                //写入日志
            }
        }