Пример #1
0
        protected void cmdOK_Click(object sender, EventArgs e)
        {
            try
            {
                int Service_ID = 3;

                int Customer_ID = Convert.ToInt32(ViewState["id"]);

                SalitaEntities db = new SalitaEntities();

                DateTime from = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " 12:00AM");
                DateTime to   = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " 11:59PM");

                if (db.CustomerNeeds.SingleOrDefault(p => p.Customer_ID == Customer_ID && p.RequestDateTime >= from && p.RequestDateTime <= to && p.RequestedService_ID == Service_ID && p.WasFullfilled == false) == null)
                {
                    CustomerNeed S = new CustomerNeed();

                    S.Customer_ID         = Customer_ID;
                    S.RequestDateTime     = DateTime.Now;
                    S.WasFullfilled       = false;
                    S.RequestedService_ID = Service_ID; // 3 == fuera del dealer
                    S.Address_Line        = this.txtSendTo.Text;
                    S.Town       = this.txtTown.Text;
                    S.ZipCode    = this.txtZipCode.Text;
                    S.FromDealer = (this.cmbWhereTo.SelectedIndex == 0) ? true : false;
                    S.Canceled   = false;

                    db.CustomerNeeds.Add(S);
                    db.SaveChanges();

                    if (this.cbRoundTrip.Checked)
                    {
                        S.WasFullfilled       = false;
                        S.RequestedService_ID = 4; // 4 == transportacion al dealer
                        S.RequestDateTime     = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " " + this.cmbTime.SelectedValue);
                        S.FromDealer          = !S.FromDealer;
                        db.CustomerNeeds.Add(S);
                        db.SaveChanges();
                    }

                    Response.Redirect("report_transportation.aspx");
                }
                else
                {
                    throw new Exception("Ya existe un pedido de transportación para hoy el cliente con id: " + Customer_ID.ToString());
                }
            }
            catch (Exception E)
            {
                this.CustomValidator1.IsValid      = false;
                this.CustomValidator1.ErrorMessage = E.Message;
            }
        }
Пример #2
0
        public static void SetService(int Customer_ID, int Service_ID, string Note)
        {
            SalitaEntities db = new SalitaEntities();

            var Need = new CustomerNeed();

            Need.RequestDateTime     = DateTime.Now;
            Need.Customer_ID         = Customer_ID;
            Need.WasFullfilled       = false;
            Need.Note                = Note;
            Need.RequestedService_ID = Service_ID;
            Need.Canceled            = false;

            db.CustomerNeeds.Add(Need);
            db.SaveChanges();
        }
Пример #3
0
        protected void SetService(int Customer_ID, int Service_ID)
        {
            SalitaEntities db = new SalitaEntities();

            var Need = new CustomerNeed();

            Need.RequestDateTime     = DateTime.Now;
            Need.Customer_ID         = Customer_ID;
            Need.WasFullfilled       = false;
            Need.Note                = this.txtServiceNote.Text;
            Need.RequestedService_ID = Service_ID;
            Need.Canceled            = false;

            db.CustomerNeeds.Add(Need);
            db.SaveChanges();
        }
Пример #4
0
        public static void ProcessService(int Customer_ID, int Service_ID)
        {
            SalitaEntities db = new SalitaEntities();

            if (db.CustomerNeeds.SingleOrDefault(p => p.Customer_ID == Customer_ID && p.RequestedService_ID == Service_ID && p.WasFullfilled == false) == null)
            {
                CustomerNeed S = new CustomerNeed();

                S.Customer_ID         = Customer_ID;
                S.RequestDateTime     = DateTime.Now;
                S.WasFullfilled       = false;
                S.RequestedService_ID = Service_ID;
                S.Canceled            = false;

                db.CustomerNeeds.Add(S);
                db.SaveChanges();
            }
        }
Пример #5
0
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                int RecId = 0;
                int.TryParse(Request.Form["myRecordId"].ToString(), out RecId);

                string NoteField = this.txtNotes.Value;

                // Not been saved
                var FullName = this.txtEditFullName.Value;
                var Phone    = this.txtEditPhone.Value;

                var VisitRecord = db.Visits.Single(p => p.Visit_ID == RecId);

                VisitRecord.AG_Phone = Phone;

                if (string.IsNullOrEmpty(this.cmbCompanions.Value))
                {
                    VisitRecord.AG_Companions = 0;
                }
                else
                {
                    VisitRecord.AG_Companions = Convert.ToInt32(this.cmbCompanions.Value);
                }

                VisitRecord.AG_Tag     = this.txtTag.Value;
                VisitRecord.AG_Advisor = this.txtAdvisor.Value;

                VisitRecord.AG_LL         = Convert.ToBoolean(this.cbLL.Checked);
                VisitRecord.AG_RR         = Convert.ToBoolean(this.lbR.Checked);
                VisitRecord.AG_DriveTo    = this.txtDriveTo.Value;
                VisitRecord.AG_DriverName = this.txtDriver.Value;

                VisitRecord.AG_AppointmentTime = this.txtAppointment.Value;
                VisitRecord.AG_RegisteredTime  = this.txtSignedInTime.Value;
                VisitRecord.AG_AttendedTime    = this.txtAtended.Value;
                VisitRecord.AG_ArrivalTime     = this.txtArriveTime.Value;
                VisitRecord.AG_ExitTime        = this.txtLeaveTime.Value;
                VisitRecord.AG_Comments        = NoteField;

                //VisitRecord.AG_OK = this.cbOK.Checked; // Moved to click directly on ListView

                int?Seat_X = 0;
                int?Seat_Y = 0;
                this.GetSeatCoords(1, ref Seat_X, ref Seat_Y);

                VisitRecord.Seat_X = Seat_X;
                VisitRecord.Seat_Y = Seat_Y;

                this.db.SaveChanges();

                //
                // Update CustomersNeeds table to match
                // the transportation information
                //
                bool Llevar  = VisitRecord.AG_LL.Value;
                bool Recojer = VisitRecord.AG_RR.Value;

                DateTime todayLow  = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " 12:00AM");
                DateTime todayHigh = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " 11:59PM");

                //
                // Load my current transport requests
                //
                var myTransportRequests_LLevar  = this.db.CustomerNeeds.SingleOrDefault(p => p.RequestedService_ID == 3 && p.Customer_ID == VisitRecord.Customer_ID && p.RequestDateTime >= todayLow && p.RequestDateTime <= todayHigh && p.WasFullfilled == false);
                var myTransportRequests_Recojer = this.db.CustomerNeeds.SingleOrDefault(p => p.RequestedService_ID == 4 && p.Customer_ID == VisitRecord.Customer_ID && p.RequestDateTime >= todayLow && p.RequestDateTime <= todayHigh && p.WasFullfilled == false);

                if (Llevar == false)
                {
                    //
                    // If the llevar checkbox is false then delete my current open request if any
                    //
                    if (myTransportRequests_LLevar != null)
                    {
                        this.db.CustomerNeeds.Remove(myTransportRequests_LLevar);
                        this.db.SaveChanges();
                    }
                }
                else
                {
                    if (myTransportRequests_LLevar != null)
                    {
                        myTransportRequests_LLevar.Address_Line = VisitRecord.AG_DriveTo;
                        myTransportRequests_LLevar.Note         = NoteField;
                    }
                    else
                    {
                        //
                        // Create the transportation requests
                        //
                        CustomerNeed c = new CustomerNeed();

                        c.Customer_ID         = VisitRecord.Customer_ID;
                        c.RequestedService_ID = 3; // Llevar
                        c.RequestDateTime     = DateTime.Now;
                        c.WasFullfilled       = false;
                        c.Note         = NoteField;
                        c.Address_Line = VisitRecord.AG_DriveTo;
                        c.Town         = "";
                        c.ZipCode      = "";
                        c.FromDealer   = true;
                        c.Canceled     = false;

                        this.db.CustomerNeeds.Add(c);
                    }

                    this.db.SaveChanges();
                }

                if (Recojer == false)
                {
                    if (myTransportRequests_Recojer != null)
                    {
                        this.db.CustomerNeeds.Remove(myTransportRequests_Recojer);
                        this.db.SaveChanges();
                    }
                }
                else
                {
                    if (myTransportRequests_Recojer != null)
                    {
                        myTransportRequests_Recojer.Address_Line = VisitRecord.AG_DriveTo;
                        myTransportRequests_Recojer.Note         = NoteField;
                    }
                    else
                    {
                        //
                        // Create the transportation requests
                        //
                        CustomerNeed c = new CustomerNeed();

                        c.Customer_ID         = VisitRecord.Customer_ID;
                        c.RequestedService_ID = 4; // Recojer
                        c.RequestDateTime     = DateTime.Now;
                        c.WasFullfilled       = false;
                        c.Note         = NoteField;
                        c.Address_Line = "Autogermana";
                        c.Town         = "Guaynabo";
                        c.ZipCode      = "";
                        c.FromDealer   = false;
                        c.Canceled     = false;

                        this.db.CustomerNeeds.Add(c);
                    }

                    this.db.SaveChanges();
                }

                this.LoadVisits();
            }
            catch (DbEntityValidationException dbex)
            {
                string validationErrors = "";

                foreach (var eve in dbex.EntityValidationErrors)
                {
                    validationErrors = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                     eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        validationErrors += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }

                this.CustomValidator1.IsValid      = false;
                this.CustomValidator1.ErrorMessage = validationErrors;
            }
            catch (Exception ex)
            {
                this.CustomValidator1.IsValid      = false;
                this.CustomValidator1.ErrorMessage = ex.Message;
            }
        }