Example #1
0
        private void Button2_Click(object sender, EventArgs e)
        {
            double date  = dateTimePicker2.Value.Subtract(dateTimePicker1.Value).TotalDays;
            double date1 = dateTimePicker1.Value.Subtract(DateTime.Now).TotalDays;
            double date2 = dateTimePicker2.Value.Subtract(DateTime.Now).TotalDays;

            if (date > -1 && date1 > -1 && date2 > -1)
            {
                try
                {
                    ModelObj = new editmodel(dateTimePicker1.Value, dateTimePicker2.Value, TravelID);
                    ObjController.Update(ModelObj);
                    ComboBox4_SelectedIndexChanged(sender, e);
                }
                catch (Exception er) { MessageBox.Show("Select the employee first");
                                       ComboBox4_SelectedIndexChanged(sender, e); }
            }
            else
            {
                if (date < 0 || date2 < 0)
                {
                    MessageBox.Show("Please select the correct departure date");
                }
                else if (date1 < 0)
                {
                    MessageBox.Show("Please select the correct arrival date");
                }
                ComboBox4_SelectedIndexChanged(sender, e);
            }
        }
        public void Update(editmodel Obj)
        {
            sqlDataAdapterObj            = new SqlDataAdapter();
            updateCommandObj             = new SqlCommand();
            updateCommandObj.CommandText = "update EmployeeTravelDetails set ArrivalDate=@arrivalDate,DepartureDate=@depatureDate where TravelID=@TravelID";
            updateCommandObj.Connection  = sqlConnectionObj;
            sqlParameterObj2             = new SqlParameter("@arrivalDate", Convert.ToDateTime(Obj.arrivalDate));
            sqlParameterObj3             = new SqlParameter("@depatureDate", Convert.ToDateTime(Obj.depatureDate));
            sqlParameterObj = new SqlParameter("@TravelID", Obj.TravelID);
            updateCommandObj.Parameters.Add(sqlParameterObj2);
            updateCommandObj.Parameters.Add(sqlParameterObj3);
            updateCommandObj.Parameters.Add(sqlParameterObj);

            sqlDataAdapterObj.SelectCommand = selectCommandObj;

            sqlConnectionObj.Open();
            updateCommandObj.ExecuteNonQuery();
            sqlConnectionObj.Close();
        }