示例#1
0
        private void SetUpForigenKey(string name)
        {
            IsForigenKey        = true;
            comboBox.Visibility = Visibility.Visible;
            value.Visibility    = Visibility.Collapsed;
            int       i     = 0;
            int       index = -1;
            DataTable dt;

            dt = DBSingleton.TrySelectSql(string.Format("select {0}_ID,{0}_name from {0}", name));
            if (dt == null)
            {
                dt = DBSingleton.TrySelectSql(string.Format("select {0}_ID,{0}_location from {0}", name));
            }
            if (dt == null)
            {
                dt = DBSingleton.SelectSql(string.Format("select {0}_ID,{0}_date from {0}", name));
            }
            foreach (DataRowView item in dt.AsDataView())
            {
                i++;
                if (IsForigenKey)
                {
                    if (item.Row.ItemArray[0].ToString() == originalValue)
                    {
                        index = i;
                    }
                }
                if (item.Row.ItemArray.Length > 1)
                {
                    comboBox.Items.Add(item.Row.ItemArray[0].ToString() + " - " + item.Row.ItemArray[1].ToString());
                }
                else
                {
                    comboBox.Items.Add(item.Row.ItemArray[0].ToString());
                }
            }
            if (IsForigenKey)
            {
                comboBox.SelectedIndex = index;
            }
        }
示例#2
0
 public void RefreshView()
 {
     dt = DBSingleton.SelectSql(viewSql);
     mainView.ItemsSource = dt.AsDataView();
 }