Exemplo n.º 1
0
    //Add New Traveler To DataBase
    protected void buttonAddNewTraveler_Click(object sender, EventArgs e)
    {
        //Declear message Variable
        String msg = "";

        try
        {
            //checked Duplicate Traveler
            var DuplicateTraveler = TDC.TblTravelers.Where(x => x.TravelerNo.ToLower().Trim() == TextBoxTravelerNoAdd.Text.ToLower().Trim());
            if (DuplicateTraveler.Count() > 0)
            {
                //show message
                msg = " alert('Error! Duplicate Traveler Number not Allow ');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "key", msg, true);
            }
            //Create New Traveler Obbject
            var NewObj = new TblTraveler();
            NewObj.TravelerNo     = TextBoxTravelerNoAdd.Text.Trim();
            NewObj.Priority       = int.Parse(DropDownListPriorityAdd.SelectedValue);
            NewObj.OrderDate      = CalendarOrderDateAdd.SelectedDate;
            NewObj.Status         = int.Parse(DropDownListStatusAdd.SelectedValue);
            NewObj.JobDescription = TextBoxDescriptionAdd.Text;

            //Next Proccess Object
            var TravelerProcessObj = new TblTravelerProcess();
            TravelerProcessObj.ProcessAutoID = int.Parse(DropDownListNexProcessAdd.SelectedValue);
            TravelerProcessObj.DateIn        = DateTime.Now;
            NewObj.TblTravelerProcesses.Add(TravelerProcessObj);

            //add to database
            TDC.TblTravelers.InsertOnSubmit(NewObj);
            TDC.SubmitChanges();

            //show message
            msg = " alert('Save Traveler Successful');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", msg, true);

            //Refresh Traveler info Grid
            LoadTravelerInfoGrid();
        }
        catch (Exception)
        {
            //show message
            msg = " alert('Error To Save Traveler');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", msg, true);
        }
    }
 partial void DeleteTblTraveler(TblTraveler instance);
 partial void UpdateTblTraveler(TblTraveler instance);
 private void detach_TblTravelers(TblTraveler entity)
 {
     this.SendPropertyChanging();
     entity.TblStatus = null;
 }
 partial void InsertTblTraveler(TblTraveler instance);
 private void attach_TblTravelers(TblTraveler entity)
 {
     this.SendPropertyChanging();
     entity.TblPriority = this;
 }