Exemplo n.º 1
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            if (lvCustomers.Items.Count < 1)
            {
                MessageBox.Show("请先加载数据到列表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }
            if (cmbProjects.Text == String.Empty)
            {
                if (DialogResult.No == MessageBox.Show("您确定不指定项目?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    return;
                }
            }
            if (MessageBox.Show("您确认要将数据加入项目【" + cmbProjects.Text + "】,并指定数据来源为【" + cmbCustomerSources.Text + "】吗?",
                                "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            ImportCustomerVo vo = new ImportCustomerVo();

            if (cmbProjects.Text != String.Empty)
            {
                vo.projectId = Convert.ToInt32(cmbProjects.SelectedValue.ToString());
            }
            vo.source    = Convert.ToInt32(cmbCustomerSources.SelectedValue.ToString());
            vo.remark    = txtRemark.Text.Trim();
            vo.customers = new List <CustomerData>();
            foreach (ListViewItem lvi in lvCustomers.Items)
            {
                vo.customers.Add((CustomerData)lvi.Tag);
            }
            try
            {
                Cursor = Cursors.WaitCursor;
                Int32 count = CustomerService.ImportCustomerData(vo, Global.USER_TOKEN);
                Cursor = Cursors.Default;
                if (DialogResult.Yes != MessageBox.Show("成功导入数据( " + count + " 条)!您是否需要继续导入新的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    DialogResult = DialogResult.OK;
                    return;
                }
                lvCustomers.Items.Clear();
                txtFile.Text                     = String.Empty;
                labelCount.Text                  = "0";
                cmbProjects.SelectedIndex        = 0;
                cmbCustomerSources.SelectedIndex = 0;
                butOpen.Focus();
            }
            catch (BusinessException ex)
            {
                Cursor = Cursors.Default;
                MessageBox.Show("导入数据失败:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 导入客户
        /// </summary>
        /// <param name="customers">客户列表</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Int32 ImportCustomerData(ImportCustomerVo vo, String token)
        {
            RestClient rc      = new RestClient();
            var        request = new RestRequest(GlobalConfig.IMPORT_CUSTOMERS);

            request.AddHeader(GlobalConfig.AUTHORIZATION, token);
            request.AddJsonBody(vo);
            IRestResponse response;

            try
            {
                response = rc.Execute(request, Method.POST);
            }
            catch (Exception ex)
            {
                throw new BusinessException(ex.Message);
            }
            if (response.StatusCode == 0)
            {
                throw new BusinessException("请检查网络");
            }
            if (response.StatusCode != HttpStatusCode.OK)
            {
                var res             = rc.Deserialize <CustomException>(response);
                var customException = res.Data;
                throw new BusinessException(customException.message);
            }
            try
            {
                var types = rc.Deserialize <Int32>(response);
                return(types.Data);
            }
            catch (Exception ex)
            {
                throw new BusinessException(ex.Message);
            }
        }