Beispiel #1
0
 private void ClearControls()
 {
     CustomerNameTextBox.Clear();
     CustomerMobileTextBox.Clear();
     CustomerAddressTextBox.Clear();
     CustomerNameTextBox.Focus();
 }
Beispiel #2
0
 private void AddCustomer()
 {
     if (CustomerNameTextBox.Text.Length > 3 && CustomerCodeTextBox.Text.Length > 3)
     {
         Customer cust = new Customer()
         {
             CustomerCode = CustomerCodeTextBox.Text,
             Name         = CustomerNameTextBox.Text,
             EntryDate    = DateTime.Now
         };
         if (context.Customers.SingleOrDefault(c => c.CustomerCode == cust.CustomerCode) != null)
         {
             MessageBox.Show("Cannot create duplicate");
         }
         else
         {
             context.Customers.Add(cust);
             context.SaveChanges();
         }
     }
     else
     {
         CustomerNameTextBox.Select();
     }
 }
        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;
        }
Beispiel #4
0
 private void GenerateCustomerCode()
 {
     if (CustomerNameTextBox.Text.Length > 3)
     {
         Random random       = new Random();
         string CustomerCode = "";
         string hexa         = "abcdefghjkmnpqruvwxyz";
         int    a            = 1;
         int    b            = 20;
         int    c            = 9;
         int    d            = 99;
         int    e            = 999;
         CustomerCode += hexa.Substring(random.Next(0, b), 1).ToUpper();
         CustomerCode += (random.Next(a, d)).ToString("0");
         CustomerCode += hexa.Substring(random.Next(0, b), 1).ToUpper();
         CustomerCode += (random.Next(a, e)).ToString("0");
         if (context.Customers.SingleOrDefault(p => p.CustomerCode == CustomerCode) != null)
         {
             CustomerCode += (random.Next(a, c)).ToString("0");
         }
         CustomerCodeTextBox.Text = CustomerCode;
     }
     else
     {
         CustomerNameTextBox.Select();
     }
 }
Beispiel #5
0
        private void ForceValidation()
        {
            if (NoNIPCheckBox.IsChecked == false)
            {
                NIPTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            }

            if (NoREGONCheckBox.IsChecked == false)
            {
                REGONTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            }

            if (NoBankAccountCheckBox.IsChecked == false)
            {
                BankAccountNumberTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            }

            CustomerNameTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            CityTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            ZipCodeTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            FlatNumberTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            StreetNumberTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            StreetTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            PhoneNumberTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
        }
Beispiel #6
0
 private void clear()
 {
     StoreNameTextBox.Clear();
     PickupTimeDateTimePicker.ResetText();
     CoversNumeric.Value = 0;
     CustomerNameTextBox.Clear();
     MemberNumberTextBox.Clear();
     CommentsTextBox.Clear();
     RespondCheckBox.Checked         = false;
     PaymentRequiredCheckBox.Checked = false;
 }
Beispiel #7
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);
        }
Beispiel #8
0
        public void ClearCustomerTextBoxes()
        {
            // RB sets all text boxes value to empty string
            CustomerIDTextBox.Text       = "";
            CustomerNameTextBox.Text     = "";
            CustomerLastNameTextBox.Text = "";
            CustomerAddressTextBox.Text  = "";

            // RB Set focus to Customer Name Field
            CustomerNameTextBox.Select();
        }
Beispiel #9
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;
            }
        }
        /// <summary>
        /// Tìm xem khách hàng này có trong CSDL không
        /// </summary>
        private void customerPhoneTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var telCustomer = customerPhoneTextBox.Text;
            var db          = new MyShopEntities();

            customer = db.Customers.Find(telCustomer);//Tìm số điện thoại trong CSDL

            //Tìm thấy tên khách hàng theo số điện thoại
            if (customer != null)
            {
                CustomerNameTextBox.Text = customer.Fullname;//Lấy tên tương ướng với SDT
            }
            else
            {
                CustomerNameTextBox.Clear();
            }
        }
Beispiel #11
0
        internal void RefreshTabCustomer()
        {
            customerBindingSource.Clear();
            for (int i = 0; i < manager.Customers.Count; i++)
            {
                customerBindingSource.Add(manager.Customers[i]);
            }
            CustomerNameTextBox.Clear();
            CustomerSurnameTextBox.Clear();
            CountryTextBox.Clear();
            AgreementDateTimePicker.Value = DateTime.Now;
            CustomerDataGridView.ClearSelection();


            for (int i = 0; i < manager.Customers.Count; i++)
            {
                LoadProjectInfoToCustomer(manager.Customers[i]);
            }
        }
Beispiel #12
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();
 }