예제 #1
0
 private void ClearControls()
 {
     CustomerNameTextBox.Clear();
     CustomerMobileTextBox.Clear();
     CustomerAddressTextBox.Clear();
     CustomerNameTextBox.Focus();
 }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CustomerNameTextBox.Text))
            {
                return;
            }

            this.Cursor = Cursors.Wait;

            try
            {
                using (ThirtyOneEntities toe = new ThirtyOneEntities())
                {
                    Customer cust = toe.Customers.SingleOrDefault(t => t.CustomerName == CustomerNameTextBox.Text.Trim());

                    if (cust != null)
                    {
                        this.Cursor = Cursors.Arrow;
                        MessageBox.Show("Customer already exists.");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                string error = string.Format("{0}{1}{2}{3}", ex.Message, Environment.NewLine, (ex.InnerException != null) ? ex.InnerException.Message : "", ex.StackTrace);
                MessageBox.Show(error);
                return;
            }

            try
            {
                using (ThirtyOneEntities te = new ThirtyOneEntities())
                {
                    Customer c = te.CreateObject <Customer>();
                    c.CustomerID   = Guid.NewGuid();
                    c.CustomerName = CustomerNameTextBox.Text.Trim();

                    te.Customers.AddObject(c);
                    te.SaveChanges();
                }

                CustomerNameTextBox.Text = string.Empty;
                OnCustomerAddCompleted();

                Storyboard saveCompleteSB = (Storyboard)FindResource("SaveCompleteStoryboard");
                saveCompleteSB.Begin();

                CustomerNameTextBox.Focus();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                MessageBox.Show(ex.Message);
                return;
            }

            this.Cursor = Cursors.Arrow;
        }
예제 #3
0
        private bool IsValid()
        {
            if (CustomerNameTextBox.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Customer Name is required!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                CustomerNameTextBox.Focus();
                return(false);
            }

            return(true);
        }
예제 #4
0
        private void CustomerNameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Regex namePattern = new Regex("^[A-Z].[A-Za-z]* [A-Z].[A-Za-z]* *[A-Za-z]*");

            if (!namePattern.IsMatch(CustomerNameTextBox.Text))
            {
                MessageBox.Show($"Please enter a valid customer name.", "Width Input Error");
                CustomerNameTextBox.Text      = string.Empty;
                CustomerNameTextBox.BackColor = Color.MistyRose;
                CustomerNameTextBox.Focus();
            }
            else
            {
                CustomerNameTextBox.BackColor = Color.Honeydew;
            }
        }
예제 #5
0
        private void Save(string action)
        {
            HttpClient client = new HttpClient();

            client.Timeout = TimeSpan.FromMinutes(15);
            string         URL            = "";
            string         bodyString     = "";
            string         projectJS      = "";
            string         returnMessage  = "";
            Project        project        = new Project();
            ResultProjects resultProjects = new ResultProjects();

            project.CustomerID  = Data.GlovalVariables.currentCustomerID;
            project.ProjectName = ProjectNameTextBox.Text;

            switch (Data.GlovalVariables.transactionType)
            {
            case "New":

                projectJS  = JsonConvert.SerializeObject(project, Newtonsoft.Json.Formatting.Indented);
                URL        = BaseURL + "Projects/NewProject";
                bodyString = "'" + projectJS + "'";

                HttpContent body_for_new = new StringContent(bodyString);
                body_for_new.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                HttpResponseMessage response_for_new = client.PostAsync(URL, body_for_new).Result;

                using (HttpContent content = response_for_new.Content)
                {
                    Task <string> resultTemp = content.ReadAsStringAsync();
                    returnMessage = resultTemp.Result;
                    // Reformating the result string
                    //returnMessage = returnMessage.Replace(@"\n", "\n").Replace(@"\r", "\r").Replace("\\", "");
                    //returnMessage = returnMessage.Remove(returnMessage.Length - 1, 1).Substring(1);
                    resultProjects = JsonConvert.DeserializeObject <ResultProjects>(returnMessage);
                }

                if (response_for_new.IsSuccessStatusCode)
                {
                    // Set the value of the new project to a gloval variable
                    if (resultProjects.ReturnCode == -1)
                    {
                        MessageBox.Show("Warning:" + "\r\n" + resultProjects.Message.Replace(". ", "\r\n"), "New Project Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        Data.GlovalVariables.newProjectsList.Add(ProjectNameTextBox.Text);
                        if (action == "SaveAndExit")
                        {
                            this.Close();
                        }
                        else
                        {
                            ProjectNameTextBox.Text = "";
                            ProjectNameTextBox.Focus();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Error:" + "\r\n" + resultProjects.Message.Replace(". ", "\r\n") + resultProjects.Exception, "New Project Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                break;

            case "Update":
                project.ProjectID = Data.GlovalVariables.currentProjectID;
                projectJS         = JsonConvert.SerializeObject(project, Newtonsoft.Json.Formatting.Indented);
                URL        = BaseURL + "Projects/UpdateProject";
                bodyString = "'" + projectJS + "'";

                HttpContent body_for_update = new StringContent(bodyString);
                body_for_update.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                HttpResponseMessage response_for_update = client.PostAsync(URL, body_for_update).Result;

                using (HttpContent content = response_for_update.Content)
                {
                    Task <string> resultTemp = content.ReadAsStringAsync();
                    returnMessage = resultTemp.Result;
                    // Reformating the result string
                    returnMessage  = returnMessage.Replace(@"\n", "\n").Replace(@"\r", "\r").Replace("\\", "");
                    returnMessage  = returnMessage.Remove(returnMessage.Length - 1, 1).Substring(1);
                    resultProjects = JsonConvert.DeserializeObject <ResultProjects>(returnMessage);
                }

                if (response_for_update.IsSuccessStatusCode)
                {
                    // Set the value of the new project to a gloval variable
                    if (resultProjects.ReturnCode == -1)
                    {
                        MessageBox.Show("Warning:" + "\r\n" + resultProjects.Message.Replace(". ", "\r\n"), "Update Projects Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        Data.GlovalVariables.currentProjectName = ProjectNameTextBox.Text;
                        if (action == "SaveAndExit")
                        {
                            this.Close();
                        }
                        else
                        {
                            CustomerNameTextBox.Focus();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Error:" + "\r\n" + resultProjects.Message.Replace(". ", "\r\n"), "Update Project Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                break;
            }
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     CustomerNameTextBox.Focus();
 }