// GET: api/Customer
        public List <CustomerDTO> Get(string searchfield = null, string searchstring = null, string sortby = "fullname", int pagenumber = 1, int pagesize = 100, bool asc = true)
        {
            IQueryable <customer> ListCus;

            if (searchstring != null && searchfield != null)
            {
                ListCus = _customerService.Search(searchstring, searchfield, sortby, asc);
            }
            else
            {
                ListCus = _customerService.Sort(sortby, asc);
            }
            ListCus = _customerService.Paging(ListCus, pagenumber, pagesize);
            return(Mapper.Map <List <CustomerDTO> >(ListCus.ToList()));
        }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            KhachHang newCus = controls_Load();

            if (TestData())
            {
                if (ListCus.Add(newCus))
                {
                    MessageBox.Show("Adding is success full!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    return;
                }
                MessageBox.Show("Adding had been faile!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void Customerfrm_Load(object sender, EventArgs e)
        {
            //new da truyen tu frm me thi khoi load
            if (listOrder == null)
            {
                listOrder = new List <Chuyen>();
            }
            if (ListTours == null)
            {
                ListTours = new ToursList();
            }
            if (ListTrips == null)
            {
                ListTrips = new Trips();
            }
            if (ListCus == null)
            {
                ListCus = new CusList();
            }
            if (ListOrd == null)
            {
                ListOrd = new OrderList();
            }

            tvTours_Load(ListTours.FindByStatus("Đang mở"));
            if (Code != null)
            {
                btnAdd.Enabled = false;
                btnAdd.Visible = false;
                controls_BindData(ListCus.Single(Code));
            }
            else
            {
                btnUpdate.Visible = false;
                txtCode.Text      = NewBestIDCustomer();
                Code = txtCode.Text;
            }
        }
Esempio n. 4
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtAddress.Text.ToUpper().Contains(cbbCountries.SelectedItem.ToString().ToUpper()))
            {
                MessageBox.Show("The address must not have the country!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAddress.Focus();
                return;
            }

            if (cbbCity.Enabled && cbbCity.SelectedIndex > 0 && txtAddress.Text.ToUpper().Contains(cbbCity.SelectedItem.ToString().ToUpper()))
            {
                MessageBox.Show("The address must not have the city!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cbbCity.Focus();
                return;
            }

            KhachHang oldCus = ListCus.Single(txtCode.Text);
            KhachHang newCus = controls_Load();

            if (oldCus.Ho.ToUpper() != newCus.Ho.ToUpper() || oldCus.Ten.ToUpper() != newCus.Ten.ToUpper())
            {
                if (!ListCus.Test(txtFirstName.Text + " " + txtName.Text, txtAddress.Text, (cbbCity.Enabled && (cbbCity.SelectedIndex > 0)) ? cbbCity.SelectedItem.ToString() : "", cbbCountries.SelectedItem.ToString()))
                {
                    MessageBox.Show("This customer had been exited!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtAddress.Focus();
                    return;
                }
            }

            if (ListCus.Update(newCus))
            {
                MessageBox.Show("Udating is success full!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                return;
            }
            MessageBox.Show("Update had been faile!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Esempio n. 5
0
        private bool TestData()
        {
            if (txtAddress.Text.ToUpper().Contains(cbbCountries.SelectedItem.ToString().ToUpper()))
            {
                MessageBox.Show("The address must not have the country!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAddress.Focus();
                return(false);
            }

            if (cbbCity.Enabled && cbbCity.SelectedIndex > 0 && txtAddress.Text.ToUpper().Contains(cbbCity.SelectedItem.ToString().ToUpper()))
            {
                MessageBox.Show("The address must not have the city!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cbbCity.Focus();
                return(false);
            }

            if (!ListCus.Test(txtFirstName.Text + " " + txtName.Text, txtAddress.Text, (cbbCity.Enabled && (cbbCity.SelectedIndex > 0)) ? cbbCity.SelectedItem.ToString() : "", cbbCountries.SelectedItem.ToString()))
            {
                MessageBox.Show("This customer had been exited!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAddress.Focus();
                return(false);
            }
            return(true);
        }
Esempio n. 6
0
        private void btnRequireOrder_Click(object sender, EventArgs e)
        {
            if (ListCus.Single(txtCode.Text) != null)
            {
                if (listOrder.Count > 0)
                {
                    //Tao ra danh sach dat cho
                    List <DatCho> temp = new List <DatCho>();
                    DatCho        t    = new DatCho();
                    foreach (Chuyen item in listOrder)
                    {
                        t.MChuyen = item.MChuyen;
                        t.MKHang  = txtCode.Text;
                        temp.Add(t);
                    }

                    //Tim danh sach dat cho da ton tai va co trang thai chuyen di la dang cho
                    List <Chuyen> oldTrip = ListTrips.Find(ListOrd.Find(Code), 1);//Tim ds chuyen dang mo cua ds dat cho cua khach hang
                    //Tao ds dat cho cua khach hang da ton tai va trang thai dang mo
                    List <DatCho> old = new List <DatCho>();
                    foreach (Chuyen item in oldTrip)
                    {
                        DatCho tp = new DatCho();
                        tp.MKHang  = txtCode.Text;
                        tp.MChuyen = item.MChuyen;
                        old.Add(tp);
                    }

                    // So sanh voi temp de lay ra nhung cai them moi va nhung cai can xoa di
                    List <DatCho> nw = new List <DatCho>(); //danh sach can them moi
                    List <DatCho> dl = new List <DatCho>(); //danh sach can xoa di
                    foreach (DatCho i in temp)
                    {
                        bool s = true;
                        foreach (DatCho j in old)
                        {
                            if (i.MChuyen == j.MChuyen)//da ton tai, bo qua
                            {
                                s = false;
                                break;
                            }
                        }
                        if (s)
                        {
                            nw.Add(i);//Chua ton tai nen them duoc
                        }
                    }

                    foreach (DatCho i in old)
                    {
                        bool r = true;
                        foreach (DatCho j in temp)
                        {
                            if (i.MChuyen == j.MChuyen)
                            {
                                r = false;
                                break;
                            }
                        }
                        if (r)//co trong cai cu nhung khong co trong cai moi nen xoa di
                        {
                            dl.Add(i);
                        }
                    }
                    // duong nhien ca hai old va temp deu la danh sach dat cho cua chuyen dang mo
                    // Thuc hien xoa tren old va add tren nw la OK

                    foreach (DatCho i in nw)
                    {
                        if (ListOrd.Add(i))
                        {
                            MessageBox.Show(String.Format("You have add the trip which has code {0}!", i.MChuyen), "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            MessageBox.Show(String.Format("You had been faile the trip which has code {0}!", i.MChuyen), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    foreach (DatCho i in dl)
                    {
                        if (ListOrd.Delete(i))
                        {
                            MessageBox.Show(String.Format("You have delete the trip which has code {0}!", i.MChuyen), "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            MessageBox.Show(String.Format("You had been faile the trip which has code {0}!", i.MChuyen), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    btnRequireOrder.Enabled = false;
                }
                else
                {
                    MessageBox.Show("You have not add the trips! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("You have not add this customer! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }