Exemple #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            VPBLL.Company.CompanyHelper cHelper = new VPBLL.Company.CompanyHelper();
            VPBLL.Vendor.VenderHelper vHelper=new VPBLL.Vendor.VenderHelper();
            List<VPBLL.Company.ABiCompany> companyList = cHelper.getCompanyByCode(this.companyCode.Value);
            if (companyList != null && companyList.Count > 0)//判定是否有该公司
            {
                List<VPBLL.Vendor.ABiVendor> vendorList = vHelper.getABiVendorByCode(this.vendorCode.Value);
                if (vendorList == null || vendorList.Count == 0)
                {
                    VPBLL.Vendor.ABiVendor vendor = new VPBLL.Vendor.ABiVendor();
                    vendor.VendorCode = this.vendorCode.Value;
                    vendor.VendorName = this.vendorName.Value;
                    vendor.TaxNumber = this.taxNumber.Value;
                    vendor.IndustryCode = this.industryCode.Value;
                    vendor.DateCreated = Convert.ToDateTime(DateTime.Now);
                    vendor.DateModified = Convert.ToDateTime(DateTime.Now);
                    vendor.Blocking = "";
                    vendor.Deletion = "";
                    vHelper.addVendor(vendor);//保存vendor
                    vendorList = vHelper.getABiVendorByCode(this.vendorCode.Value);//获取到新的venderID
                    vendor = vendorList[0];
                    VPBLL.Vendor.AbiBankAccount bank = new VPBLL.Vendor.AbiBankAccount();
                    bank.ABi_Vendor_ID = vendor.ABi_Vendor_ID;
                    bank.BankCode = this.bankCode.Value;
                    bank.BankName = this.bankName.Value;
                    bank.BankAccount = this.bankAccount.Value;
                    bank.ReceiverName = this.receiverName.Value;
                    vHelper.addBankAccount(bank);
                    VPBLL.Company.ABiCompany company = companyList[0];
                    VPBLL.Vendor.ABiVendor_Company vendor_Company = new VPBLL.Vendor.ABiVendor_Company();
                    vendor_Company.ABi_Vendor_ID = vendor.ABi_Vendor_ID;
                    vendor_Company.ABi_Company_ID = Convert.ToInt32(company.ID);
                    vendor_Company.Blocking ="";
                    vendor_Company.Deletion = "";
                    vendor_Company.PaymentTerm = this.paymentTerm.Value;
                    vHelper.addVendorCompany(vendor_Company);
                    ClientScript.RegisterStartupScript(GetType(), "alertpwd", "<script>alert('保存成功');back();</script>");

                }
                else
                    ClientScript.RegisterStartupScript(GetType(), "alertpwd", "<script>alert('该供应商已存在')</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "alertpwd", "<script>alert('该公司编号无效')</script>");
            }
        }
Exemple #2
0
        public override DataSet Import(System.Data.DataSet ds)
        {
            var failedRows = new DataSet();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dtFailed = new DataTable("Failed_Imported");
                DataColumn[] columns = new DataColumn[ds.Tables[0].Columns.Count + 1];
                for (int i = 0; i < ds.Tables[0].Columns.Count; ++i)
                {
                    columns[i] = new DataColumn(ds.Tables[0].Columns[i].ColumnName);
                }
                columns[ds.Tables[0].Columns.Count] = new DataColumn("错误原因");
                dtFailed.Columns.AddRange(columns);

                BuildHeader(ds.Tables[0].Columns);
                VPBLL.Vendor.VenderHelper vHelper = new VPBLL.Vendor.VenderHelper();
                VPBLL.Vendor.ABiVendor vendor = new VPBLL.Vendor.ABiVendor();
                VPBLL.Company.CompanyHelper cHelper = new VPBLL.Company.CompanyHelper();
                for (int i = 0; i < ds.Tables[0].Rows.Count; ++i)
                {
                    vendor.VendorCode = GetFieldValue(ds.Tables[0].Rows[i], "供应商代码").ToString();
                    vendor.VendorName = GetFieldValue(ds.Tables[0].Rows[i], "供应商名称").ToString();
                    List<VPBLL.Vendor.ABiVendor> vendorList = vHelper.getABiVendorByCode(vendor.VendorCode);
                    string companyCode = GetFieldValue(ds.Tables[0].Rows[i], "公司代码").ToString();
                    List<VPBLL.Company.ABiCompany> companyList = cHelper.getCompanyByCode(companyCode);
                    if (String.IsNullOrEmpty(vendor.VendorCode) || String.IsNullOrEmpty(vendor.VendorName))
                    {
                        List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray);
                        row.Add(String.Format("供应商编号为空或供应商名称为空{0},{1}", vendor.VendorCode, vendor.VendorName));
                        dtFailed.Rows.Add(row.ToArray());
                    }
                    else if(string.IsNullOrEmpty(companyCode))
                    {
                         List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray);
                         row.Add(String.Format("公司编号为空{0},{1}", companyCode));
                        dtFailed.Rows.Add(row.ToArray());
                    }
                    else if (companyList == null || companyList.Count == 0)
                    {
                        List<object> row = new List<object>(ds.Tables[0].Rows[i].ItemArray);
                        row.Add(String.Format("未找到该公司{0},{1}", companyCode));
                        dtFailed.Rows.Add(row.ToArray());
                    }
                    else
                    {
                        VPBLL.Company.ABiCompany company = companyList[0];

                        try
                        {
                            vendor.TaxNumber = GetFieldValue(ds.Tables[0].Rows[i], "纳税人识别号").ToString();
                            vendor.IndustryCode = GetFieldValue(ds.Tables[0].Rows[i], "所属行业").ToString();
                            vendor.DateCreated = Convert.ToDateTime(DateTime.Now);
                            vendor.DateModified = Convert.ToDateTime(DateTime.Now);
                            vendor.Blocking = "";
                            vendor.Deletion = "";
                            if (vendorList == null || vendorList.Count == 0)//新增vendor
                            {

                                vHelper.addVendor(vendor);//保存vendor
                                vendorList = vHelper.getABiVendorByCode(vendor.VendorCode);//获取到新的venderID
                                vendor = vendorList[0];
                                VPBLL.Vendor.AbiBankAccount bank = new VPBLL.Vendor.AbiBankAccount();
                                bank.ABi_Vendor_ID = vendor.ABi_Vendor_ID;
                                bank.BankCode = GetFieldValue(ds.Tables[0].Rows[i], "供应商开户行").ToString();
                                bank.BankName = GetFieldValue(ds.Tables[0].Rows[i], "供应商开户名称").ToString();
                                bank.BankAccount = GetFieldValue(ds.Tables[0].Rows[i], "供应商银行帐号").ToString();
                                bank.ReceiverName = GetFieldValue(ds.Tables[0].Rows[i], "收款人名称").ToString();
                                vHelper.addBankAccount(bank);

                                VPBLL.Vendor.ABiVendor_Company vendor_Company = new VPBLL.Vendor.ABiVendor_Company();
                                vendor_Company.ABi_Vendor_ID = vendor.ABi_Vendor_ID;
                                vendor_Company.ABi_Company_ID = Convert.ToInt32(company.ID);
                                vendor_Company.Blocking = "";
                                vendor_Company.Deletion = "";
                                vendor_Company.PaymentTerm = GetFieldValue(ds.Tables[0].Rows[i], "付款周期").ToString();
                                vHelper.addVendorCompany(vendor_Company);
                            }
                            else
                            {
                                vHelper.updateVendor(vendor);
                                VPBLL.Vendor.AbiBankAccount bank = new VPBLL.Vendor.AbiBankAccount();
                                vendorList = vHelper.getABiVendorByCode(vendor.VendorCode);//获取到新的venderID
                                vendor = vendorList[0];
                                bank.ABi_Vendor_ID = vendor.ABi_Vendor_ID;
                                bank.BankCode = GetFieldValue(ds.Tables[0].Rows[i], "供应商开户行").ToString();
                                bank.BankName = GetFieldValue(ds.Tables[0].Rows[i], "供应商开户名称").ToString();
                                bank.BankAccount = GetFieldValue(ds.Tables[0].Rows[i], "供应商银行帐号").ToString();
                                bank.ReceiverName = GetFieldValue(ds.Tables[0].Rows[i], "收款人名称").ToString();
                                List<AbiBankAccount> bankList = vHelper.getABiBankAccount(bank.ABi_Vendor_ID, bank.BankCode);
                                if (bankList == null || bankList.Count == 0)
                                    vHelper.addBankAccount(bank);
                                else
                                    vHelper.updateBankAccount(bank);
                                VPBLL.Vendor.ABiVendor_Company vendor_Company = new VPBLL.Vendor.ABiVendor_Company();
                                vendor_Company.ABi_Vendor_ID = vendor.ABi_Vendor_ID;
                                vendor_Company.ABi_Company_ID = Convert.ToInt32(company.ID);
                                vendor_Company.PaymentTerm = GetFieldValue(ds.Tables[0].Rows[i], "付款周期").ToString();
                                vHelper.addVendorCompany(vendor_Company);
                            }
                        }
                        catch (Exception ex)
                        {
                            var row = new List<object>(ds.Tables[0].Rows[i].ItemArray);
            #if DEBUG
                            row.Add(String.Format("出现异常错误:{0}", ex.Message));
            #else
                            row.Add(String.Format("出现异常错误"));
            #endif
                            dtFailed.Rows.Add(row.ToArray());
                            logger.LogError(String.Format("Failed VendorImport({0},{1})", vendor.VendorCode, vendor.VendorName), ex);
                        }

                    }
                }

                failedRows.Tables.Add(dtFailed);
            }
            return failedRows;
        }