public MainWindow()
        {
            this.Height = SystemParameters.PrimaryScreenHeight;                                                                                 //获取当前设备的屏幕分辨率高度作为程序高度
            this.Width  = this.Height * (double)Properties.Resources.Sign_In_BackGround.Width / Properties.Resources.Sign_In_BackGround.Height; //根据屏幕分辨率高度计算出与背景图片比例合适的程序宽度

            Sign_in Temp = new Sign_in();                                                                                                       //弹出并指定登录界面

            InitializeComponent();

            this.FillDataGrid();//加载当前帐户的联系人数据
        }
        private void Click_Insert(object sender, RoutedEventArgs e)
        {
            if (this.Insert_Name.Text.Equals(string.Empty))
            {
                System.Windows.MessageBox.Show("Empty Name Inserted!");
            }
            else
            {
                using (SqlConnection con = new SqlConnection(Properties.Settings.Default.DataBaseConnectionString))
                {
                    try
                    {
                        SqlCommand     cmd     = new SqlCommand("SELECT Name,City,Tel,QQ,Belong FROM Contactors WHERE Belong='" + Sign_in.Get_Confidential_User_ID().Trim() + "'", con);
                        SqlDataAdapter AutoSda = new SqlDataAdapter();
                        AutoSda.SelectCommand = cmd;
                        SqlCommandBuilder ComBuild = new SqlCommandBuilder(AutoSda);
                        con.Open();
                        DataTable dt = new DataTable();
                        AutoSda.Fill(dt);
                        DataRow [] Rows_Selected = dt.Select("Name='" + this.Insert_Name.Text.Trim() + "'");
                        if (Rows_Selected.Count() == 0)
                        {
                            Insert_Detail Item = new Insert_Detail(this.Insert_Name.Text.Trim(), Insert_Verifycode);
                            this.Insert_Name.Text = "输入名字";

                            Object[] temp = new Object[5];
                            temp[0] = ContactData.Get_Name();
                            temp[1] = ContactData.Get_City();
                            temp[2] = ContactData.Get_Tel();
                            temp[3] = ContactData.Get_QQ();
                            temp[4] = Sign_in.Get_Confidential_User_ID();
                            dt.LoadDataRow(temp, true);
                            dt.AcceptChanges();
                            AutoSda.Update(dt);
                            Contact_Book_View.ItemsSource = dt.DefaultView;
                        }
                        else
                        {
                            System.Windows.MessageBox.Show(Name + " is already existed!");
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
Exemple #3
0
        public MainWindow()
        {
            try
            {
                Sign_in Logging = new Sign_in();
                Logging.Close();
                Running_Confidential_Value = Sign_in.Get_Confidential_Level();
                Refresh_DataGrid();
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message + "10549");
            }

            InitializeComponent();
        }
Exemple #4
0
        private void Click_Insert(object sender, RoutedEventArgs e)
        {
            if (this.Insert_Name.Text.Equals(string.Empty))
            {
                System.Windows.MessageBox.Show("Empty Name Inserted!");
            }
            else
            {
                DataTable      Dt = new DataTable();
                SqlDataAdapter Temp_DataAdapter = new SqlDataAdapter();
                SqlConnection  Temp_Link        = Get_Connect_DataBase();
                Temp_DataAdapter.SelectCommand = new SqlCommand("select * from Contactors where Belonging='" + Sign_in.Get_Confidential_User_ID() + "';", Temp_Link);
                SqlCommandBuilder SCB = new SqlCommandBuilder(Temp_DataAdapter);


                try
                {
                    Temp_DataAdapter.Fill(Dt);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message + "\t4wefsdf8647");
                }
                try
                {
                    DataRow Insert_Row = Dt.NewRow();
                    Insert_Row["Name"]      = ContactData.Get_Name();
                    Insert_Row["City"]      = ContactData.Get_City();
                    Insert_Row["Tel"]       = ContactData.Get_Tel();
                    Insert_Row["QQ"]        = ContactData.Get_QQ();
                    Insert_Row["Belonging"] = Sign_in.Get_Confidential_User_ID();
                    Dt.ImportRow(Insert_Row);
                    Temp_DataAdapter.Update(Dt);

                    Dt.AcceptChanges();
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message + "\t489797");
                }
                finally
                {
                    Temp_Link.Close();
                }
            }
        }
 private void FillDataGrid()
 {
     //大概过程---先配置数据库ConString(因为配置文件App.config把数据库名字改成了这个),作用是说明在配置文件里直接就可以修改数据库的参数而不用麻烦的在代码里改
     //--然后定义一个字符串用作写T-SQL语句,然后初始化数据库连接(使用配置文件ConString),字符串放T-sql语句
     //--再然后数据库命令,作用是使得上一句的字符串的命令生效
     //--再然后实例化SqlDataAdapter
     //---再然后实例化数据表DataTable
     //---再然后SqlDataAdapter填充数据表DataTable的东西
     //--最后把填充好的数据的基础视图赋值给DataGrid的ItemSource
     using (SqlConnection con = new SqlConnection(Properties.Settings.Default.DataBaseConnectionString))
     {
         SqlCommand     cmd = new SqlCommand("SELECT Name,City,Tel,QQ,Belong FROM Contactors WHERE Belong='" + Sign_in.Get_Confidential_User_ID().Trim() + "'", con);
         SqlDataAdapter sda = new SqlDataAdapter(cmd);
         DataTable      dt  = new DataTable();
         sda.Fill(dt);
         Contact_Book_View.ItemsSource = dt.DefaultView;
     }
 }
        private void Click_Log_Out(object sender, RoutedEventArgs e)
        {
            Sign_in Temp = new Sign_in();

            InitializeComponent();
        }
 private void Click_Search(object sender, RoutedEventArgs e)
 {
     //System.Windows.MessageBox.Show("Searching "+this.Search_Name.Text);
     if (this.Search_Name.Text.Trim().Equals(string.Empty))
     {
         System.Windows.MessageBox.Show("Empty Name Inserted!");
     }
     else
     {
         using (SqlConnection con = new SqlConnection(Properties.Settings.Default.DataBaseConnectionString))
         {
             try
             {
                 SqlCommand     cmd     = new SqlCommand("SELECT Name,City,Tel,QQ,Belong FROM Contactors WHERE Belong='" + Sign_in.Get_Confidential_User_ID().Trim() + "'", con);
                 SqlDataAdapter AutoSda = new SqlDataAdapter();
                 AutoSda.SelectCommand = cmd;
                 SqlCommandBuilder ComBuild = new SqlCommandBuilder(AutoSda);
                 con.Open();
                 DataTable dt = new DataTable();
                 AutoSda.Fill(dt);
                 DataRow[] Rows_Selected = dt.Select("Name='" + this.Search_Name.Text.Trim() + "'");
                 if (Rows_Selected.Count() == 0)
                 {
                     System.Windows.MessageBox.Show(this.Search_Name.Text.Trim() + " not Found");
                 }
                 else
                 {
                     Searched_Detail temp = new Searched_Detail(Rows_Selected[0]);
                     dt.AcceptChanges();
                     AutoSda.Update(dt);
                     Contact_Book_View.ItemsSource = dt.DefaultView;
                 }
                 Search_Name.Text = "输入名字";
             }
             catch (Exception ex)
             {
                 System.Windows.MessageBox.Show(ex.Message);
             }
             finally
             {
                 con.Close();
             }
         }
     }
 }
Exemple #8
0
        private void Refresh_DataGrid()
        {
            using (SqlConnection Link = new SqlConnection(Properties.Settings.Default.SqlPath))
            {
                try
                {
                    Link.Open();
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message + "\n##Link Error##");
                }

                //SqlCommand Operation = Link.CreateCommand();

                string         CommandText = "select * from Contactors where Belonging = '" + Sign_in.Get_Confidential_User_ID().Trim() + "';";
                SqlDataAdapter DataAdapter = new SqlDataAdapter(CommandText, Link);
                DataTable      Dt          = new DataTable();
                try
                {
                    DataAdapter.Fill(Dt);
                    Contact_Book_View.ItemsSource = Dt.DefaultView;
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message + "425735");
                }

                Link.Close();
            }
        }