TXT

updatetwindow__xaml_cs

By Elsie Holmes,2014-10-12 02:31
8 views 0
updatetwindow__xaml_cs

using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Windows;

    using System.Windows.Controls;

    using System.Windows.Data;

    using System.Windows.Documents;

    using System.Windows.Input;

    using System.Windows.Media;

    using System.Windows.Media.Imaging;

    using System.Windows.Shapes;

    using System.Data;

namespace PMT

    {

     /// <summary>

     /// UpdateWindow.xaml µÄ????Âß??

     /// </summary>

     public partial class UpdateWindow : Window

     {

     public UpdateWindow(WindowMode windowMode, string recordID)

     {

     InitializeComponent();

     //********************************** Data Preparation

    ***********************************

     InitMyDataSet();

     //ComboBox for Team

     cbTeam.ItemsSource =

    DbObject.CommonDataSet.Tables["Team"].DefaultView;

     cbTeam.DisplayMemberPath = "TeamName";

     cbTeam.SelectedValuePath = "ID";

     //ComboBox for JobType

     cbJobType.ItemsSource =

    MyDataSet.Tables["JobTypeUnderPlatform"].DefaultView;

     cbJobType.DisplayMemberPath = "JobTypeName";

     cbJobType.SelectedValuePath = "ID";

     //ComboBox of Platform

     ShowTeamAllPlatform();

     cbPlatform.ItemsSource =

    MyDataSet.Tables["TeamAllPlatform"].DefaultView;

     cbPlatform.DisplayMemberPath = "PlatformName";

     cbPlatform.SelectedValuePath = "ID";

     //ComboBox of Status

     cbStatus.ItemsSource =

    DbObject.CommonDataSet.Tables["Status"].DefaultView;

     cbStatus.DisplayMemberPath = "StatusName";

     cbStatus.SelectedValuePath = "ID";

     //Set WindowID

     WindowID = GlobalVariable.UpdateWindowNumber;

     GlobalVariable.UpdateWindowNumber++;

     //Add Window into 'Opened Windows List'

     GlobalVariable.OpeningUpdateWindows.Add(WindowID, this);

     //Initialize Process

     //InitProcessListBox();

     switch (windowMode)

     {

     case WindowMode.New:

     {

     SetNewRecordWindow(recordID);

     break;

     }

     case WindowMode.Edit:

     {

     SetEditWindow(recordID);

     break;

     }

     case WindowMode.Delete:

     {

     SetDeleteWindow(recordID);

     break;

     }

     }

     }

     //************************************ Properties & Classes

************************************

     public uint WindowID { get; private set; }

     public enum WindowMode

     {

     New,

     Edit,

     Delete

     }

     private WindowMode mode;

     public WindowMode Mode

     {

     get

     {

     return mode;

     }

     set

     {

     mode = value;

     }

     }

     public static class RecordElement

     {

     public static string Team { get; set; }

     public static string Staff { get; set; }

     public static string JobType { get; set; }

     public static string Status { get; set; }

     public static string Platform { get; set; }

     public static string Subject { get; set; }

     public static string Profile { get; set; }

     public static string Comments { get; set; }

     public static int Count { get; set; }

     public static DateTime ReceiveTime { get; set; }

     public static DateTime BeginTime { get; set; }

     public static DateTime CompleteTime { get; set; }

     }

     //************************************* Procedures *******************************************

     private void tbCount_KeyDown(object sender, KeyEventArgs e)

     {

     TextBox textBox = sender as TextBox;

     int num;

     //Prevent inputting alphabets

     if (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9)

     {

     e.Handled = false;

     }

     else if (((e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key ==

    Key.OemPeriod) && e.KeyboardDevice.Modifiers != ModifierKeys.Shift)

     {

     e.Handled = false;

     }

     else if (e.Key == Key.Tab || Keyboard.Modifiers ==

    ModifierKeys.Alt)

     {

     e.Handled = false;

     }

     else

     {

     e.Handled = true;

     }

     //Function keys

     if (e.Key == Key.Add || e.Key==Key.OemPlus || e.Key==Key.Up)

     {

     num = int.Parse(textBox.Text);

     if(num < 65535) num = num + 1;

     textBox.Text = num.ToString();

     textBox.SelectAll();

     }

     else if (e.Key == Key.OemMinus || e.Key == Key.Subtract ||

    e.Key == Key.Down)

     {

     num = int.Parse(textBox.Text);

     if (num > 1) num = num - 1;

     textBox.Text = num.ToString();

     textBox.SelectAll();

     }

     //MessageBox.Show(e.Key.ToString());

     }

     private void tbCount_TextChanged(object sender,

TextChangedEventArgs e)

     {

     TextBox textBox = sender as TextBox;

     TextChange[] change = new TextChange[e.Changes.Count];

     e.Changes.CopyTo(change, 0);

     int offset = change[0].Offset;

     if (change[0].AddedLength > 0)

     {

     ushort num = 0;

     if (!ushort.TryParse(textBox.Text, out num))

     {

     textBox.Text = textBox.Text.Remove(offset,

    change[0].AddedLength);

     textBox.Select(offset, 0);

     }

     }

     if (textBox.Text == "" || ushort.Parse(textBox.Text) < 1)

     {

     textBox.Text = "1";

     textBox.SelectAll();

     }

     if (Mode == WindowMode.Edit)

     {

     if (tbCount.Text != Count)

     {

     IsCountModified = true;

     }

     }

     GetCompleteTime();

     }

     private void tbCount_GotFocus(object sender, RoutedEventArgs

    e)

     {

     TextBox textBox = sender as TextBox;

     textBox.SelectAll();

     }

     private void Button_Click(object sender, RoutedEventArgs e)

     {

     this.Close();

     }

     private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)

     {

     //Remove this window from 'Opened Windows List'

     GlobalVariable.OpeningUpdateWindows.Remove(WindowID);

     }

     private void cbJobType_SelectionChanged(object sender, SelectionChangedEventArgs e)

     {

     string selectedValue = null;

     if (cbPlatform.SelectedIndex > -1) selectedValue = GetComboxItemValue((DataRowView)cbPlatform.SelectedItem);

     MyDataSet.Tables["MyPlatform"].Clear();

     if (int.Parse(cbJobType.SelectedIndex.ToString()) >= 0)

     {

     //UpdatePlatform();

     //cbPlatform.SelectedValue = selectedValue;

     GetCompleteTime();

     if (Mode == WindowMode.Edit &&

    cbJobType.SelectedValue != null)

     {

     if (cbJobType.SelectedValue.ToString() == JobTypeID)

     {

     IsJobTypeModified = false;

     }

     else

     {

     IsJobTypeModified = true;

     }

     }

     }

     }

     private void cbTeam_SelectionChanged(object sender, SelectionChangedEventArgs e)

     {

     string selectedJobTypeValue = null;

     string selectedPlatformValue = null;

     if (this.IsLoaded)

     {

     if (cbJobType.SelectedIndex > -1)

     {

     selectedJobTypeValue =

    GetComboxItemValue((DataRowView)cbJobType.SelectedItem);

     selectedPlatformValue =

    GetComboxItemValue((DataRowView)cbPlatform.SelectedItem);

     }

     MyDataSet.Tables["MyJobType"].Clear();

     if (int.Parse(cbTeam.SelectedIndex.ToString()) >= 0)

     {

     UpdateJobType();

     ShowTeamAllPlatform();

     ComboBoxSetContent(cbJobType, selectedJobTypeValue);

     ComboBoxSetContent(cbPlatform, selectedPlatformValue);

     GetCompleteTime();

     }

     if (Mode == WindowMode.Edit && cbTeam.SelectedValue !=

    null)

     {

     if (cbTeam.SelectedValue.ToString() == TeamID)

     {

     IsTeamModified = false;

     }

     else

     {

     IsTeamModified = true;

     }

     }

     }

     }

     private void cbPlatform_SelectionChanged(object sender, SelectionChangedEventArgs e)

     {

     GetCompleteTime();

     ShowJobTypeUnderPlatform();

     if (Mode == WindowMode.Edit && cbPlatform.SelectedValue !=

null)

     {

     if (cbPlatform.SelectedValue.ToString() == PlatformID)

     {

     IsPlatformModified = false;

     }

     else

     {

     IsPlatformModified = true;

     }

     }

     }

     private void cbStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)

     {

     if (Mode == WindowMode.Edit && cbStatus.SelectedValue != null)

     {

     if (cbStatus.SelectedValue.ToString() == StatusID)

     {

     IsStatusModified = false;

     }

     else

     {

     IsStatusModified = true;

     }

     }

     }

     private void lbProcess_SelectionChanged(object sender, SelectionChangedEventArgs e)

     {

     //if (IsLoaded)

     //{

     if (lbProcess.SelectedIndex < ProcessCount && lbProcess.SelectedIndex > -1)

     {

     SeletedProcessItemTag =

    int.Parse(((ListBoxItem)lbProcess.SelectedItem).Tag.ToString()) - 1;

     dbReceiveTime.Text =

    ShowingProcess[SeletedProcessItemTag].ReceiveTime;

     dbBeginTime.Text =

    ShowingProcess[SeletedProcessItemTag].BeginTime;

     dbCompleteTime.Text = ShowingProcess[SeletedProcessItemTag].CompleteTime;

     tbComment.Text =

    ShowingProcess[SeletedProcessItemTag].Comments;

     }

     else

     {

     lbProcess.SelectedIndex = SeletedProcessItemTag;

     }

     //}

     }

     private void dbReceiveTime_TextChanged(object sender,

    TextChangedEventArgs e)

     {

     try

     {

     ShowingProcess[SeletedProcessItemTag].ReceiveTime =

    dbReceiveTime.Time.ToString("yyyy/MM/dd HH:mm");

     if (Mode == WindowMode.Edit)

     {

     if (dbReceiveTime.Text == Process[SeletedProcessItemTag].ReceiveTime)

     {

     IsReceiveTimeModified[SeletedProcessItemTag] =

    false;

     }

     else

     {

     IsReceiveTimeModified[SeletedProcessItemTag] =

    true;

     }

     }

     }

     catch { }

     }

     private void dbBeginTime_TextChanged(object sender, TextChangedEventArgs e)

     {

     try

     {

     ShowingProcess[SeletedProcessItemTag].BeginTime = dbBeginTime.Time.ToString("yyyy/MM/dd HH:mm");

     if (Mode == WindowMode.Edit)

     {

     if (dbBeginTime.Text ==

    Process[SeletedProcessItemTag].BeginTime)

     {

     IsBeginTimeModified[SeletedProcessItemTag] =

    false;

     }

     else

     {

     IsBeginTimeModified[SeletedProcessItemTag] =

    true;

     }

     }

     }

     catch { }

     }

     private void dbCompleteTime_TextChanged(object sender, TextChangedEventArgs e)

     {

     try

     {

     ShowingProcess[SeletedProcessItemTag].CompleteTime =

    dbCompleteTime.Time.ToString("yyyy/MM/dd HH:mm");

     if (Mode == WindowMode.Edit)

     {

     if (dbCompleteTime.Text == Process[SeletedProcessItemTag].CompleteTime)

     {

     IsCompleteTimeModified[SeletedProcessItemTag] =

    false;

     }

     else

     {

     IsCompleteTimeModified[SeletedProcessItemTag] =

    true;

     }

Report this document

For any questions or suggestions please email
cust-service@docsford.com