Example #1
0
 partial void DeleteTran(Tran instance);
Example #2
0
 partial void InsertTran(Tran instance);
Example #3
0
 partial void UpdateTran(Tran instance);
Example #4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["IsNew"] == "true" )
            {
                txtClosed.Visible = false;
                if (linkCustomer.Text == "")
                {
                    lblStatus.Text = "Please select a customer first.";
                    return;
                }

                Linq_1DataContext db = new Linq_1DataContext();
                Tran t = new Tran();
                t.Phone = txtPhone.Text;
                t.CstId = Convert.ToInt32(hideId.Value);
                t.Customer = hideCustomer.Value;
                t.Contact = txtContact.Text;
                t.DateAdded = DateTime.Today;
                t.Amount = Convert.ToDecimal(txtCost.Text.Replace('$','0'));
                t.Address = txtServiceAddress.Text;
                t.AssignedTo = ddTech.SelectedItem.Text;
                t.City = txtCity.Text;
                if (txtZip.Text != "")
                {
                    t.Zip = Convert.ToInt32(txtZip.Text);
                }
                t.TransactionType = 1;
                t.Status = ddStatus.SelectedItem.Text;
                t.Service = txtService.Text;
                if (txtScheduled.Text != "") { t.DateSch = Convert.ToDateTime(txtScheduled.Text); }
                if (txtClosed.Text != "") { t.DateComplete = Convert.ToDateTime(txtClosed.Text); }
                t.LastMod = DateTime.Today;
                t.Equip = txtEquipment.Text;

                db.Trans.InsertOnSubmit(t);
                //insert new record
                //Show success message + refresh
                try
                {
                    db.SubmitChanges();
                    lblStatus.Text = "New Service Request Successfully added.";
                    hideCustomer.Value = linkCustomer.Text = txtCity.Text = txtCost.Text = txtEquipment.Text = txtPhone.Text = txtScheduled.Text = txtService.Text = txtServiceAddress.Text = txtContact.Text = txtZip.Text = "";
                    CstName = "";
                    if (chkNotify.Checked == true) { Shared.EmailTicket(ddTech.SelectedItem.Text, "Customer: " + t.Customer, t.id); }
                }
                catch
                {

                }
                IsNew = false;
            }
            else
            {
                cid = Convert.ToInt32(Request.QueryString["id"]);
                //Update existing ticket
                Linq_1DataContext db = new Linq_1DataContext();
                var t = (from a in db.Trans
                         where a.id == cid
                         select a).FirstOrDefault();
                if (t != null)
                {
                    t.CstId = Convert.ToInt32(hideId.Value);
                    t.Customer = hideCustomer.Value;
                    t.Amount = Convert.ToDecimal(txtCost.Text.Replace('$', '0'));
                    t.Address = txtServiceAddress.Text;
                    t.Contact = txtContact.Text;
                    t.AssignedTo = ddTech.SelectedItem.Text;
                    t.City = txtCity.Text;
                    if (txtZip.Text != "")
                    {
                        t.Zip = Convert.ToInt32(txtZip.Text);
                    }
                    t.Phone = txtPhone.Text;
                    t.TransactionType = 1;
                    t.Status = ddStatus.SelectedItem.Text;
                    t.Service = txtService.Text;
                    if (txtScheduled.Text != "") { t.DateSch = Convert.ToDateTime(txtScheduled.Text); }
                    t.LastMod = DateTime.Today;
                    t.Equip = txtEquipment.Text;
                    if (txtClosed.Text != "") { t.DateComplete = Convert.ToDateTime(txtClosed.Text); }

                    try
                    {
                        db.SubmitChanges();
                        lblStatus.Text = "Ticket " + cid.ToString() + " has been updated.";
                    }
                    catch (FormatException et)
                    {

                            lblStatus.Text = "Incorrect date format. Please use the date picker to the right of the date textbox.";

                    }
                    catch (Exception ex)
                    {

                    }
                }

            }
        }