コード例 #1
0
        private void displayAppointmentDetails()
        {
            DataView data = (DataView)SqlDataSourceAppointment.Select(DataSourceSelectArguments.Empty);

            if (data != null && data.Count > 0)
            {
                txtAppointmentDate.Text          = data[0]["Appointment_Date"].ToString();
                DropDownListHour.SelectedValue   = data[0]["Appointment_Time"].ToString().Substring(0, 2);
                DropDownListMinute.SelectedValue = data[0]["Appointment_Time"].ToString().Substring(3, 2);
                txtPaid.Text             = data[0]["Payment"].ToString();
                chkPaid.Checked          = Convert.ToBoolean(data[0]["Paid"].ToString());
                txtComments.Text         = data[0]["Vet_Comments"].ToString();
                txtSelectedVet.Text      = data[0]["Vet"].ToString();
                txtPetID.Text            = data[0]["Pet_ID"].ToString();
                txtVetID.Text            = data[0]["Vet_ID"].ToString();
                txtSelectedPet.Text      = data[0]["Pet"].ToString();
                txtSelectedPetOwner.Text = data[0]["Pet_Owner"].ToString();
            }
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            String id = txtID.Text;

            if (id != null && id.Length > 0)
            {
                try
                {
                    SqlDataSourceInventory.UpdateCommand = "UPDATE Inventory SET Quantity = Quantity - @Quantity WHERE Medication_ID = @Medication_ID";
                    SqlDataSourceAppointment.UpdateParameters.Add("Appointment_Time", DropDownListHour.SelectedValue + ":" + DropDownListMinute.SelectedValue);
                    SqlDataSourceAppointment.Update();
                    displayMessageAlert("Appointment updated successfully.");
                }
                catch (SqlException exc)
                {
                    String errorMsg = "Error updating appointment! Please check all fields entered.";
                    displayMessageAlert(errorMsg);
                }
            }
            else
            {
                String        connectionString = ConfigurationManager.ConnectionStrings["Vet_DataConnectionString"].ConnectionString;
                SqlConnection con = new SqlConnection(connectionString);
                try
                {
                    if (txtPetID.Text == null || txtPetID.Text == "")
                    {
                        displayMessageAlert("A pet must be selected for this appointment!");
                        return;
                    }

                    if (txtVetID.Text == null || txtVetID.Text == "")
                    {
                        displayMessageAlert("A vet must be selected for this appointment!");
                        return;
                    }

                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = "sp_InsertAppointment";
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter param = new SqlParameter();
                    param.ParameterName = "@Vet_ID";
                    param.SqlDbType     = SqlDbType.Int;
                    param.Direction     = ParameterDirection.Input;
                    param.Value         = txtVetID.Text;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter();
                    param.ParameterName = "@Pet_ID";
                    param.SqlDbType     = SqlDbType.Int;
                    param.Direction     = ParameterDirection.Input;
                    param.Value         = txtPetID.Text;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter();
                    param.ParameterName = "@Payment";
                    param.SqlDbType     = SqlDbType.Money;
                    param.Direction     = ParameterDirection.Input;
                    decimal result;
                    if (decimal.TryParse(txtPaid.Text, out result))
                    {
                        param.Value = decimal.Parse(txtPaid.Text);
                    }
                    else
                    {
                        param.Value = decimal.Parse("0.00");
                    }
                    cmd.Parameters.Add(param);

                    param = new SqlParameter();
                    param.ParameterName = "@Paid";
                    param.SqlDbType     = SqlDbType.Bit;
                    param.Direction     = ParameterDirection.Input;
                    param.Value         = chkPaid.Checked;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter();
                    param.ParameterName = "@Appointment_Date";
                    param.SqlDbType     = SqlDbType.Date;
                    param.Direction     = ParameterDirection.Input;
                    param.Value         = txtAppointmentDate.Text;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter();
                    param.ParameterName = "@Appointment_Time";
                    param.SqlDbType     = SqlDbType.Time;
                    param.Direction     = ParameterDirection.Input;
                    param.Value         = DropDownListHour.SelectedValue + ":" + DropDownListMinute.SelectedValue;
                    cmd.Parameters.Add(param);

                    param = new SqlParameter();
                    param.ParameterName = "@Vet_Comments";
                    param.SqlDbType     = SqlDbType.NVarChar;
                    param.Direction     = ParameterDirection.Input;
                    param.Value         = txtComments.Text;
                    cmd.Parameters.Add(param);

                    cmd.Parameters.AddWithValue("New_ID", SqlDbType.Int).Direction = ParameterDirection.Output;

                    con.Open();
                    cmd.ExecuteNonQuery();

                    displayMessageAlert("Appointment added successfully.");
                    con.Close();

                    string newId = cmd.Parameters["New_ID"].Value.ToString();
                    txtID.Text = newId;
                }
                catch (SqlException exc)
                {
                    String errorMsg = "Error creating Appointment! Please check all fields entered.";
                    displayMessageAlert(errorMsg);
                }
            }
        }