コード例 #1
0
ファイル: AddPriestWindow.xaml.cs プロジェクト: fakeknv/PMS
        private void CreateAccountButton_Click(object sender, RoutedEventArgs e)
        {
            if (CheckInputs() == true)
            {
                dbman   = new DBConnectionManager();
                pmsutil = new PMSUtil();
                using (conn = new MySqlConnection(dbman.GetConnStr()))
                {
                    conn.Open();
                    if (conn.State == ConnectionState.Open)
                    {
                        string   uid     = Application.Current.Resources["uid"].ToString();
                        string[] dt      = pmsutil.GetServerDateTime().Split(null);
                        DateTime cDate   = Convert.ToDateTime(dt[0]);
                        DateTime cTime   = DateTime.Parse(dt[1] + " " + dt[2]);
                        string   curDate = cDate.ToString("yyyy-MM-dd");
                        string   curTime = cTime.ToString("HH:mm:ss");

                        string       pid = pmsutil.GenPriestID();
                        MySqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText =
                            "INSERT INTO residing_priests(priest_id, priest_name, priest_status, created_by, date_created, time_created)" +
                            "VALUES(@priest_id, @priest_name, @priest_status, @created_by, @date_created, @time_created)";
                        cmd.Prepare();
                        cmd.Parameters.AddWithValue("@priest_id", pid);
                        cmd.Parameters.AddWithValue("@priest_name", PriestName.Text);
                        cmd.Parameters.AddWithValue("@priest_status", Status.Text);
                        cmd.Parameters.AddWithValue("@created_by", uid);
                        cmd.Parameters.AddWithValue("@date_created", curDate);
                        cmd.Parameters.AddWithValue("@time_created", curTime);
                        int stat_code = cmd.ExecuteNonQuery();
                        conn.Close();
                        if (stat_code > 0)
                        {
                            _caller.SyncPriest();
                            pmsutil.LogAccount("Added priest - Name: " + PriestName.Text);
                            MsgSuccess();
                            this.Close();
                        }
                        else
                        {
                            MsgFail();
                        }
                    }
                    else
                    {
                    }
                }
            }
            else
            {
            }
        }