Exemplo n.º 1
0
        public FrmCustomerInfo(Customer cus)
        {
            InitializeComponent();

            _customer = cus;
            
            InitBinding();
        }
Exemplo n.º 2
0
        internal static bool ImportCustomerList(string fileName, string sheetName)
        {

            DataTable dtExcel = GetExcelTable(fileName, sheetName);
            if (dtExcel == null) return false;

            try
            {
                dtExcel.Columns[0].Unique = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("contains non-unique values"))
                    EasyDialog.ShowWarningDialog(string.Format("Sheet [{0}] có những dòng trùng mã khách hàng", sheetName));
                else
                    EasyDialog.ShowWarningDialog("Sheet excel [" + sheetName + "] dùng để import không hợp lệ");
                return false;
            }
          
            int iCount = 0;
            foreach (DataRow dr in dtExcel.Rows)
            {
                try
                {
                    string tenKH = Convert.IsDBNull(dr["TÊN KHÁCH HÀNG"]) ? string.Empty : dr["TÊN KHÁCH HÀNG"].ToString();
                    if (tenKH == string.Empty)
                    {
                        EasyDialog.ShowWarningDialog("Tên khách hàng không được rỗng.\nVui lòng kiểm tra dữ liệu trước khi import");
                        return false;
                    }
                    Customer cus = Customer.FindObject<Customer>("CustomerName", tenKH);
                    if (cus == null)
                    {
                        cus = new Customer();
                    }
                   
                    cus.CustomerName = tenKH;
                    cus.Phone = Convert.ToString(dr["ĐIỆN THOẠI"]);
                    cus.Address = Convert.ToString(dr["ĐỊA CHỈ"]);
                    cus.TaxCode = Convert.ToString(dr["MÃ SỐ THUẾ"]);
                    cus.Fax = Convert.ToString(dr["FAX"]);
                    cus.Email = Convert.ToString(dr["EMAIL"]);
                    cus.BankAccount = Convert.ToString(dr["TÀI KHOẢN NGÂN HÀNG"]);
                    cus.Note = Convert.ToString(dr["GHI CHÚ"]);
                    cus.Save();
                    iCount++;

                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("does not belong to table"))
                    {
                        EasyDialog.ShowWarningDialog("Sheet excel [" + sheetName + "] dùng để import không hợp lệ");
                        return false;
                    }
                }
            }

            EasyDialog.ShowSuccessfulDialog(string.Format("Đã import {0} khách hàng", iCount));

            return true;
        }