예제 #1
0
        public Cleaning AddCleaning(Cleaning cleaning)
        {
            var serviceQuery = new SqlCommand(@"INSERT INTO Service (StartDate, EndDate, TramFk) VALUES (@startdate, @enddate, @tramfk); SELECT SCOPE_IDENTITY();");

            serviceQuery.Parameters.AddWithValue("@startdate", cleaning.StartDate);
            if (cleaning.EndDate == null)
            {
                serviceQuery.Parameters.AddWithValue("@enddate", DBNull.Value);
            }
            else
            {
                serviceQuery.Parameters.AddWithValue("@enddate", cleaning.EndDate);
            }
            serviceQuery.Parameters.AddWithValue("@tramfk", cleaning.TramId);

            var data = Database.GetData(serviceQuery);

            var cleaningQuery = new SqlCommand(@"INSERT INTO Clean (ServiceFk, Size, Remarks) VALUES (@id, @size, @remarks)");

            cleaningQuery.Parameters.AddWithValue("@id", data.Rows[0].ItemArray[0]);
            cleaningQuery.Parameters.AddWithValue("@size", (int)cleaning.Size);
            cleaningQuery.Parameters.AddWithValue("@remarks", cleaning.Comments ?? "");
            Database.GetData(cleaningQuery);

            cleaning.SetId(Convert.ToInt32((decimal)data.Rows[0].ItemArray[0]));
            SetUsersToServices(cleaning);

            return(cleaning);
        }
예제 #2
0
        public void UpdateCleaninginDatabase(User activeUser, Form targetform, DateTime startdate, DateTime?enddate,
                                             ComboBox sortsrvc_cb, RichTextBox commenttb, List <User> users, TextBox tramnrtb, Cleaning toupdatecleaning)
        {
            var cleaning = new Cleaning(startdate, enddate, (CleaningSize)sortsrvc_cb.SelectedIndex,
                                        commenttb.Text, users, Convert.ToInt32(tramnrtb.Text));

            cleaning.SetId(toupdatecleaning.Id);
            _repo.EditService(cleaning);

            targetform.Close();
        }