Exemple #1
0
    public void SaveDataToDB(string FullPath, string FileName, string excelFileExtension)
    {
        SqlTransaction transaction = null;

        try {
            DataTable dt = null;
            dt = this.GetDataSet(FullPath, excelFileExtension).Tables[0];
            if (dt.Rows.Count <= 1)
            {
                PageUtility.ShowModelDlg(this.Page, "文件中没有任何记录,请重新选择");
                return;
            }
            ShopTableAdapter            TAShop            = new ShopTableAdapter();
            ImportLogTableAdapter       TAImportLog       = new ImportLogTableAdapter();
            ImportLogDetailTableAdapter TAImportLogDetail = new ImportLogDetailTableAdapter();
            MasterDataBLL mdBLL = new MasterDataBLL();

            transaction = TableAdapterHelper.BeginTransaction(TAShop);
            TableAdapterHelper.SetTransaction(TAImportLog, transaction);
            TableAdapterHelper.SetTransaction(TAImportLogDetail, transaction);
            //存储log信息
            ImportDS.ImportLogDataTable logTable = new ImportDS.ImportLogDataTable();
            ImportDS.ImportLogRow       logRow   = logTable.NewImportLogRow();

            int    stuffUserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
            string fullname    = this.fileUpLoad.PostedFile.FileName.ToString();
            string tmpFile     = fullname.Remove(0, fullname.LastIndexOf("\\") + 1);
            logRow.FileName     = tmpFile;
            logRow.ImportDate   = DateTime.Now;
            logRow.ImportUserID = stuffUserID;
            logRow.ImportType   = 4;
            logRow.TotalCount   = dt.Rows.Count - 1;
            logRow.SuccessCount = dt.Rows.Count - 1;
            logRow.FailCount    = 0;
            logTable.AddImportLogRow(logRow);
            TAImportLog.Update(logTable);

            //处理每条明细
            ERS.ShopDataTable tbShop = new ERS.ShopDataTable();
            ImportDS.ImportLogDetailDataTable ImportLogDetailTable = new ImportDS.ImportLogDetailDataTable();
            int    row_count  = dt.Rows.Count;
            string errorInfor = string.Empty;
            //  int expenseTypeID = int.Parse(ExpenseTypeDDL.SelectedValue);
            //开始处理每条明细
            for (int i = 1; i <= row_count - 1; i++)
            {
                if (CheckData(dt.Rows[i]) != null)
                {
                    errorInfor = "第" + (i + 1) + "行有错:" + CheckData(dt.Rows[i]);
                    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    ImportDetailRow.LogID = logRow.LogID;
                    ImportDetailRow.Line  = i + 1;
                    ImportDetailRow.Error = errorInfor;
                    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    logRow.FailCount    = logRow.FailCount + 1;
                    logRow.SuccessCount = logRow.SuccessCount - 1;
                    TAImportLog.Update(logRow);
                    continue;
                }
                else
                {
                    DataRow row           = dt.Rows[i];
                    string  ShopName      = row[0].ToString().Trim();
                    string  ShopNo        = row[1].ToString().Trim();
                    string  CustomerName  = row[2].ToString().Trim();
                    string  ShopLevelName = row[3].ToString().Trim();
                    string  Address       = row[4].ToString().Trim();
                    string  Contacter     = row[5].ToString().Trim();
                    string  Telephone     = row[6].ToString().Trim();
                    string  Email         = row[7].ToString().Trim();

                    ERS.CustomerDataTable tbCustomer = mdBLL.GetCustomerByCustomerName(CustomerName);

                    if (tbCustomer == null || tbCustomer.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:找不到客户《" + CustomerName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.ShopLevelDataTable tbShopLevel = mdBLL.GetShopLevelByShopLevelName(ShopLevelName);

                    if (tbShopLevel == null || tbShopLevel.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:找不到门店等级《" + ShopLevelName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }
                    int iCount = (int)new ShopTableAdapter().SearchNameByIns(ShopName, tbCustomer[0].CustomerID, tbShopLevel[0].ShopLevelID);
                    if (iCount > 0)
                    {
                        errorInfor = string.Format("第" + (i + 1) + "行有错:同一客户,同一门店等级({0})下门店名称({1})不能重复!", tbShopLevel[0].ShopLevelName, ShopName);
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.ShopRow rowShop = tbShop.NewShopRow();

                    //string ShopName = row[0].ToString().Trim();
                    //string ShopNo = row[1].ToString().Trim();
                    //string CustomerNo = row[2].ToString().Trim();
                    //string CustomerName = row[3].ToString().Trim();
                    //string ShopLevelName = row[4].ToString().Trim();
                    //string Address = row[5].ToString().Trim();
                    //string Contacter = row[6].ToString().Trim();
                    //string Telephone = row[7].ToString().Trim();
                    //string Email = row[8].ToString().Trim();

                    rowShop.ShopName    = ShopName;
                    rowShop.ShopNo      = ShopNo;
                    rowShop.CustomerID  = tbCustomer[0].CustomerID;
                    rowShop.ShopLevelID = tbShopLevel[0].ShopLevelID;
                    rowShop.Address     = Address;
                    rowShop.Contacter   = Contacter;
                    rowShop.Tel         = Telephone;
                    rowShop.Email       = Email;
                    rowShop.IsActive    = true;

                    tbShop.AddShopRow(rowShop);
                    TAShop.Update(rowShop);
                }
            }
            TAImportLog.Update(logRow);
            TAImportLogDetail.Update(ImportLogDetailTable);

            transaction.Commit();
            string returnString = "成功导入" + logRow.SuccessCount.ToString() + "条信息";
            PageUtility.ShowModelDlg(this.Page, returnString);
        } catch (Exception ex) {
            if (transaction != null)
            {
                transaction.Rollback();
            }
            PageUtility.ShowModelDlg(this.Page, "Save Fail!" + ex.ToString());
        } finally {
            if (transaction != null)
            {
                transaction.Dispose();
            }
        }
    }
Exemple #2
0
    public void SaveDataToDB(string FullPath, string FileName, string excelFileExtension)
    {
        SqlTransaction transaction = null;
        try {
            DataTable dt = null;
            dt = this.GetDataSet(FullPath, excelFileExtension).Tables[0];
            if (dt.Rows.Count <= 1) {
                PageUtility.ShowModelDlg(this.Page, "�ļ���û���κμ�¼��������ѡ��");
                return;
            }
            ShopTableAdapter TAShop = new ShopTableAdapter();
            ImportLogTableAdapter TAImportLog = new ImportLogTableAdapter();
            ImportLogDetailTableAdapter TAImportLogDetail = new ImportLogDetailTableAdapter();
            MasterDataBLL mdBLL = new MasterDataBLL();

            transaction = TableAdapterHelper.BeginTransaction(TAShop);
            TableAdapterHelper.SetTransaction(TAImportLog, transaction);
            TableAdapterHelper.SetTransaction(TAImportLogDetail, transaction);
            //�洢log��Ϣ
            ImportDS.ImportLogDataTable logTable = new ImportDS.ImportLogDataTable();
            ImportDS.ImportLogRow logRow = logTable.NewImportLogRow();

            int stuffUserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
            string fullname = this.fileUpLoad.PostedFile.FileName.ToString();
            string tmpFile = fullname.Remove(0, fullname.LastIndexOf("\\") + 1);
            logRow.FileName = tmpFile;
            logRow.ImportDate = DateTime.Now;
            logRow.ImportUserID = stuffUserID;
            logRow.ImportType = 4;
            logRow.TotalCount = dt.Rows.Count - 1;
            logRow.SuccessCount = dt.Rows.Count - 1;
            logRow.FailCount = 0;
            logTable.AddImportLogRow(logRow);
            TAImportLog.Update(logTable);

            //����ÿ����ϸ
            ERS.ShopDataTable tbShop = new ERS.ShopDataTable();
            ImportDS.ImportLogDetailDataTable ImportLogDetailTable = new ImportDS.ImportLogDetailDataTable();
            int row_count = dt.Rows.Count;
            string errorInfor = string.Empty;
            //  int expenseTypeID = int.Parse(ExpenseTypeDDL.SelectedValue);
            //��ʼ����ÿ����ϸ
            for (int i = 1; i <= row_count - 1; i++) {
                if (CheckData(dt.Rows[i]) != null) {
                    errorInfor = "��" + (i + 1) + "����" + CheckData(dt.Rows[i]);
                    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    ImportDetailRow.LogID = logRow.LogID;
                    ImportDetailRow.Line = i + 1;
                    ImportDetailRow.Error = errorInfor;
                    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    logRow.FailCount = logRow.FailCount + 1;
                    logRow.SuccessCount = logRow.SuccessCount - 1;
                    TAImportLog.Update(logRow);
                    continue;
                } else {
                    DataRow row = dt.Rows[i];
                    string ShopName = row[0].ToString().Trim();
                    string ShopNo = row[1].ToString().Trim();
                    string CustomerName = row[2].ToString().Trim();
                    string ShopLevelName = row[3].ToString().Trim();
                    string Address = row[4].ToString().Trim();
                    string Contacter = row[5].ToString().Trim();
                    string Telephone = row[6].ToString().Trim();
                    string Email = row[7].ToString().Trim();

                    ERS.CustomerDataTable tbCustomer = mdBLL.GetCustomerByCustomerName(CustomerName);

                    if (tbCustomer == null || tbCustomer.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д���Ҳ����ͻ���" + CustomerName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.ShopLevelDataTable tbShopLevel = mdBLL.GetShopLevelByShopLevelName(ShopLevelName);

                    if (tbShopLevel == null || tbShopLevel.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д���Ҳ����ŵ�ȼ���" + ShopLevelName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }
                    int iCount =(int) new ShopTableAdapter().SearchNameByIns(ShopName, tbCustomer[0].CustomerID, tbShopLevel[0].ShopLevelID);
                    if (iCount > 0) {
                        errorInfor = string.Format("��" + (i + 1) + "���д��ͬһ�ͻ���ͬһ�ŵ�ȼ�({0})���ŵ�����({1})�����ظ���",tbShopLevel[0].ShopLevelName,ShopName);
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.ShopRow rowShop = tbShop.NewShopRow();

                    //string ShopName = row[0].ToString().Trim();
                    //string ShopNo = row[1].ToString().Trim();
                    //string CustomerNo = row[2].ToString().Trim();
                    //string CustomerName = row[3].ToString().Trim();
                    //string ShopLevelName = row[4].ToString().Trim();
                    //string Address = row[5].ToString().Trim();
                    //string Contacter = row[6].ToString().Trim();
                    //string Telephone = row[7].ToString().Trim();
                    //string Email = row[8].ToString().Trim();

                    rowShop.ShopName = ShopName;
                    rowShop.ShopNo = ShopNo;
                    rowShop.CustomerID = tbCustomer[0].CustomerID;
                    rowShop.ShopLevelID = tbShopLevel[0].ShopLevelID;
                    rowShop.Address = Address;
                    rowShop.Contacter = Contacter;
                    rowShop.Tel = Telephone;
                    rowShop.Email = Email;
                    rowShop.IsActive = true;

                    tbShop.AddShopRow(rowShop);
                    TAShop.Update(rowShop);
                }
            }
            TAImportLog.Update(logRow);
            TAImportLogDetail.Update(ImportLogDetailTable);

            transaction.Commit();
            string returnString = "�ɹ�����" + logRow.SuccessCount.ToString() + "����Ϣ";
            PageUtility.ShowModelDlg(this.Page, returnString);
        } catch (Exception ex) {
            if (transaction != null) {
                transaction.Rollback();
            } PageUtility.ShowModelDlg(this.Page, "Save Fail!" + ex.ToString());
        } finally {
            if (transaction != null) {
                transaction.Dispose();
            }
        }
    }
Exemple #3
0
    public void SaveDataToDB(string FullPath, string FileName, string excelFileExtension)
    {
        SqlTransaction transaction = null;

        try {
            DataTable dt = null;
            dt = this.GetDataSet(FullPath, excelFileExtension).Tables[0];
            if (dt.Rows.Count <= 1)
            {
                PageUtility.ShowModelDlg(this.Page, "文件中没有任何记录,请重新选择");
                return;
            }
            BudgetSalesFeeTableAdapter  TABudgetSalesFee  = new BudgetSalesFeeTableAdapter();
            ImportLogTableAdapter       TAImportLog       = new ImportLogTableAdapter();
            ImportLogDetailTableAdapter TAImportLogDetail = new ImportLogDetailTableAdapter();

            transaction = TableAdapterHelper.BeginTransaction(TABudgetSalesFee);
            TableAdapterHelper.SetTransaction(TAImportLog, transaction);
            TableAdapterHelper.SetTransaction(TAImportLogDetail, transaction);
            //存储log信息
            ImportDS.ImportLogDataTable logTable = new ImportDS.ImportLogDataTable();
            ImportDS.ImportLogRow       logRow   = logTable.NewImportLogRow();

            int    stuffUserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
            string fullname    = this.fileUpLoad.PostedFile.FileName.ToString();
            string tmpFile     = fullname.Remove(0, fullname.LastIndexOf("\\") + 1);
            logRow.FileName     = tmpFile;
            logRow.ImportDate   = DateTime.Now;
            logRow.ImportUserID = stuffUserID;
            logRow.ImportType   = 2;
            logRow.TotalCount   = dt.Rows.Count - 1;
            logRow.SuccessCount = dt.Rows.Count - 1;
            logRow.FailCount    = 0;
            logTable.AddImportLogRow(logRow);
            TAImportLog.Update(logTable);

            //处理每条明细
            BudgetDS.BudgetSalesFeeDataTable  BudgetSalesTable     = new BudgetDS.BudgetSalesFeeDataTable();
            ImportDS.ImportLogDetailDataTable ImportLogDetailTable = new ImportDS.ImportLogDetailDataTable();
            int    row_count  = dt.Rows.Count;
            string errorInfor = string.Empty;
            //  int expenseTypeID = int.Parse(ExpenseTypeDDL.SelectedValue);
            //开始处理每条明细
            for (int i = 1; i <= row_count - 1; i++)
            {
                if (CheckData(dt.Rows[i]) != null)
                {
                    errorInfor = "第" + (i + 1) + "行有错:" + CheckData(dt.Rows[i]);
                    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    ImportDetailRow.LogID = logRow.LogID;
                    ImportDetailRow.Line  = i + 1;
                    ImportDetailRow.Error = errorInfor;
                    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    logRow.FailCount    = logRow.FailCount + 1;
                    logRow.SuccessCount = logRow.SuccessCount - 1;
                    TAImportLog.Update(logRow);
                    continue;
                }
                else
                {
                    DataRow row               = dt.Rows[i];
                    string  CustomerName      = row[0].ToString().Trim();
                    string  CustomerNo        = row[1].ToString().Trim();
                    string  Period_Year       = row[2].ToString().Trim();
                    string  Period_Month      = row[3].ToString().Trim();
                    string  AccountingCode    = row[4].ToString().Trim();
                    string  ExpenseManageType = row[5].ToString().Trim();
                    string  OriginalBudget    = row[6].ToString().Trim();
                    string  NormalBudget      = row[7].ToString().Trim();
                    string  AdjustBudget      = row[8].ToString().Trim();
                    string  TransferBudget    = row[9].ToString().Trim();
                    string  Remark            = row[11].ToString().Trim();

                    ERS.CustomerDataTable customerTable = new MasterDataBLL().GetCustomerPaged(0, 20, string.Format("CustomerNo='{0}'", CustomerNo), null);

                    if (customerTable == null || customerTable.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:系统中找不到此客户《" + CustomerNo + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }
                    else if (customerTable.Count > 1)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:系统中找到多个此编号的客户《" + CustomerNo + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }
                    else
                    {
                        ERS.ExpenseItemDataTable expenseItemTable = new MasterDataBLL().GetExpenseItemPaged(0, 20, null, string.Format("AccountingCode='{0}'", AccountingCode));
                        if (expenseItemTable == null || expenseItemTable.Count == 0)
                        {
                            errorInfor = "第" + (i + 1) + "行有错:系统中找不到此费用类别《" + AccountingCode + "》";
                            ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                            ImportDetailRow.LogID = logRow.LogID;
                            ImportDetailRow.Line  = i + 1;
                            ImportDetailRow.Error = errorInfor;
                            ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                            logRow.FailCount    = logRow.FailCount + 1;
                            logRow.SuccessCount = logRow.SuccessCount - 1;
                            TAImportLog.Update(logRow);
                            continue;
                        }
                        else if (expenseItemTable.Count > 1)
                        {
                            errorInfor = "第" + (i + 1) + "行有错:系统中找到多个此费用类别《" + AccountingCode + "》";
                            ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                            ImportDetailRow.LogID = logRow.LogID;
                            ImportDetailRow.Line  = i + 1;
                            ImportDetailRow.Error = errorInfor;
                            ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                            logRow.FailCount    = logRow.FailCount + 1;
                            logRow.SuccessCount = logRow.SuccessCount - 1;
                            TAImportLog.Update(logRow);
                            continue;
                        }
                        else
                        {
                            string temp   = Period_Year + "-" + Period_Month + "-01";
                            string filter = string.Format("CustomerID = {0} and ExpenseItemID= {1} and Period = '{2}'", customerTable[0].CustomerID, expenseItemTable[0].ExpenseItemID, DateTime.Parse(Period_Year + "-" + Period_Month + "-01"));
                            if (new BudgetBLL().GetPagedBudgetSalesFee(filter, 0, 20, null).Count > 0)
                            {
                                errorInfor = "第" + (i + 1) + "行有错:系统中已经存在本年月的预算信息,请在系统中直接更新";
                                ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                                ImportDetailRow.LogID = logRow.LogID;
                                ImportDetailRow.Line  = i + 1;
                                ImportDetailRow.Error = errorInfor;
                                ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                                logRow.FailCount    = logRow.FailCount + 1;
                                logRow.SuccessCount = logRow.SuccessCount - 1;
                                TAImportLog.Update(logRow);
                                continue;
                            }
                            else
                            {
                                BudgetDS.BudgetSalesFeeRow BudgetSalesRow = BudgetSalesTable.NewBudgetSalesFeeRow();
                                BudgetSalesRow.CustomerID     = customerTable[0].CustomerID;
                                BudgetSalesRow.Period         = DateTime.Parse(Period_Year + "-" + Period_Month + "-01");
                                BudgetSalesRow.ExpenseItemID  = expenseItemTable[0].ExpenseItemID;
                                BudgetSalesRow.OriginalBudget = decimal.Parse(OriginalBudget);
                                BudgetSalesRow.NormalBudget   = decimal.Parse(NormalBudget);
                                BudgetSalesRow.AdjustBudget   = decimal.Parse(AdjustBudget);
                                BudgetSalesRow.TransferBudget = decimal.Parse(TransferBudget);
                                BudgetSalesRow.TotalBudget    = decimal.Round(BudgetSalesRow.NormalBudget + BudgetSalesRow.AdjustBudget, 2);
                                BudgetSalesRow.ModifyReason   = Remark;
                                BudgetSalesTable.AddBudgetSalesFeeRow(BudgetSalesRow);
                            }
                        }
                    }
                }
            }
            TAImportLog.Update(logRow);
            TAImportLogDetail.Update(ImportLogDetailTable);
            TABudgetSalesFee.Update(BudgetSalesTable);
            transaction.Commit();
            string returnString = "成功导入" + logRow.SuccessCount.ToString() + "条信息";
            PageUtility.ShowModelDlg(this.Page, returnString);
        } catch (Exception ex) {
            if (transaction != null)
            {
                transaction.Rollback();
            }
            PageUtility.ShowModelDlg(this.Page, "Save Fail!" + ex.ToString());
        } finally {
            if (transaction != null)
            {
                transaction.Dispose();
            }
        }
    }
    public void SaveDataToDB(string FullPath, string FileName, string excelFileExtension)
    {
        SqlTransaction transaction = null;
        try {
            DataTable dt = null;
            dt = this.GetDataSet(FullPath, excelFileExtension).Tables[0];
            if (dt.Rows.Count <= 1) {
                PageUtility.ShowModelDlg(this.Page, "�ļ���û���κμ�¼��������ѡ��");
                return;
            }
            BudgetManageFeeTableAdapter TABudgetManageFee = new BudgetManageFeeTableAdapter();
            ImportLogTableAdapter TAImportLog = new ImportLogTableAdapter();
            ImportLogDetailTableAdapter TAImportLogDetail = new ImportLogDetailTableAdapter();

            transaction = TableAdapterHelper.BeginTransaction(TABudgetManageFee);
            TableAdapterHelper.SetTransaction(TAImportLog, transaction);
            TableAdapterHelper.SetTransaction(TAImportLogDetail, transaction);
            //�洢log��Ϣ
            ImportDS.ImportLogDataTable logTable = new ImportDS.ImportLogDataTable();
            ImportDS.ImportLogRow logRow = logTable.NewImportLogRow();

            int stuffUserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
            string fullname = this.fileUpLoad.PostedFile.FileName.ToString();
            string tmpFile = fullname.Remove(0, fullname.LastIndexOf("\\") + 1);
            logRow.FileName = tmpFile;
            logRow.ImportDate = DateTime.Now;
            logRow.ImportUserID = stuffUserID;
            logRow.ImportType = 1;
            logRow.TotalCount = dt.Rows.Count - 1;
            logRow.SuccessCount = dt.Rows.Count - 1;
            logRow.FailCount = 0;
            logTable.AddImportLogRow(logRow);
            TAImportLog.Update(logTable);

            //����ÿ����ϸ
            BudgetDS.BudgetManageFeeDataTable BudgetManageTable = new BudgetDS.BudgetManageFeeDataTable();
            ImportDS.ImportLogDetailDataTable ImportLogDetailTable = new ImportDS.ImportLogDetailDataTable();
            int row_count = dt.Rows.Count;
            string errorInfor = string.Empty;
            //  int expenseTypeID = int.Parse(ExpenseTypeDDL.SelectedValue);
            //��ʼ����ÿ����ϸ
            for (int i = 1; i <= row_count - 1; i++) {
                if (CheckData(dt.Rows[i]) != null) {
                    errorInfor = "��" + (i + 1) + "����" + CheckData(dt.Rows[i]);
                    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    ImportDetailRow.LogID = logRow.LogID;
                    ImportDetailRow.Line = i + 1;
                    ImportDetailRow.Error = errorInfor;
                    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    logRow.FailCount = logRow.FailCount+1;
                    logRow.SuccessCount = logRow.SuccessCount-1;
                    TAImportLog.Update(logRow);
                    continue;
                } else {
                    DataRow row = dt.Rows[i];
                    string DepartmentName = row[0].ToString().Trim();
                    string Period_Year = row[1].ToString().Trim();
                    string Period_Month = row[2].ToString().Trim();
                    string AccountingCode = row[3].ToString().Trim();
                    string ExpenseManageType = row[4].ToString().Trim();
                    string OriginalBudget = row[5].ToString().Trim();
                    string NormalBudget = row[6].ToString().Trim();
                    string AdjustBudget = row[7].ToString().Trim();
                    string Remark = row[9].ToString().Trim();

                    AuthorizationDS.OrganizationUnitDataTable ouTable = new OUTreeBLL().GetDataByOrganizationUnitName(DepartmentName);

                    if (ouTable == null || ouTable.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д��ϵͳ���Ҳ����˲��š�" + DepartmentName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount+1;
                        logRow.SuccessCount = logRow.SuccessCount-1;
                        TAImportLog.Update(logRow);
                        continue;
                    } else if (ouTable.Count > 1) {
                        errorInfor = "��" + (i + 1) + "���д��ϵͳ���ҵ���������ƵIJ��š�" + DepartmentName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount+1;
                        logRow.SuccessCount = logRow.SuccessCount-1;
                        TAImportLog.Update(logRow);
                        continue;
                    } else {

                        ERS.ExpenseManageTypeDataTable emtTable = new MasterDataBLL().GetExpenseManageTypePaged(0, 20, string.Format("AccountingCode = '{0}'", AccountingCode), null);
                        if (emtTable == null || emtTable.Count == 0) {
                            errorInfor = "��" + (i + 1) + "���д��ϵͳ���Ҳ����˷������" + AccountingCode + "��";
                            ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                            ImportDetailRow.LogID = logRow.LogID;
                            ImportDetailRow.Line = i + 1;
                            ImportDetailRow.Error = errorInfor;
                            ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                            logRow.FailCount = logRow.FailCount+1;
                            logRow.SuccessCount = logRow.SuccessCount-1;
                            TAImportLog.Update(logRow);
                            continue;
                        } else if (emtTable.Count > 1) {
                            errorInfor = "��" + (i + 1) + "���д��ϵͳ���ҵ�����˷������" + AccountingCode + "��";
                            ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                            ImportDetailRow.LogID = logRow.LogID;
                            ImportDetailRow.Line = i + 1;
                            ImportDetailRow.Error = errorInfor;
                            ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                            logRow.FailCount = logRow.FailCount+1;
                            logRow.SuccessCount = logRow.SuccessCount-1;
                            TAImportLog.Update(logRow);
                            continue;
                        } else {
                            string temp = Period_Year + "-" + Period_Month + "-01";
                            string filter = string.Format("OrganizationUnitID = {0} and ExpenseManageTypeID= {1} and Period = '{2}'", ouTable[0].OrganizationUnitId, emtTable[0].ExpenseManageTypeID, DateTime.Parse(Period_Year + "-" + Period_Month + "-01"));
                            if (new BudgetBLL().GetPagedBudgetManageFee(filter, 0, 20, null).Count > 0) {
                                errorInfor = "��" + (i + 1) + "���д��ϵͳ���Ѿ����ڱ����µ�Ԥ����Ϣ������ϵͳ��ֱ�Ӹ���";
                                ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                                ImportDetailRow.LogID = logRow.LogID;
                                ImportDetailRow.Line = i + 1;
                                ImportDetailRow.Error = errorInfor;
                                ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                                logRow.FailCount = logRow.FailCount+1;
                                logRow.SuccessCount = logRow.SuccessCount-1;
                                TAImportLog.Update(logRow);
                                continue;
                            } else {
                                BudgetDS.BudgetManageFeeRow BudgetManageRow = BudgetManageTable.NewBudgetManageFeeRow();
                                BudgetManageRow.OrganizationUnitID = ouTable[0].OrganizationUnitId;
                                BudgetManageRow.Period = DateTime.Parse(Period_Year + "-" + Period_Month + "-01");
                                BudgetManageRow.ExpenseManageTypeID = emtTable[0].ExpenseManageTypeID;
                                BudgetManageRow.OriginalBudget = decimal.Parse(OriginalBudget);
                                BudgetManageRow.NormalBudget = decimal.Parse(NormalBudget);
                                BudgetManageRow.AdjustBudget = decimal.Parse(AdjustBudget);
                                BudgetManageRow.TotalBudget = decimal.Round(BudgetManageRow.NormalBudget + BudgetManageRow.AdjustBudget, 2);
                                BudgetManageRow.ModifyReason = Remark;
                                BudgetManageTable.AddBudgetManageFeeRow(BudgetManageRow);
                            }
                        }
                    }
                }
            }
            TAImportLog.Update(logRow);
            TAImportLogDetail.Update(ImportLogDetailTable);
            TABudgetManageFee.Update(BudgetManageTable);
            transaction.Commit();
            string returnString = "�ɹ�����" + logRow.SuccessCount.ToString() + "����Ϣ";
            PageUtility.ShowModelDlg(this.Page, returnString);
        } catch (Exception ex) {
            if (transaction != null) {
                transaction.Rollback();
            } PageUtility.ShowModelDlg(this.Page, "Save Fail!" + ex.ToString());
        } finally {
            if (transaction != null) {
                transaction.Dispose();
            }
        }
    }
Exemple #5
0
    public void SaveDataToDB(string FullPath, string FileName, string excelFileExtension)
    {
        SqlTransaction transaction = null;
        try {
            DataTable dt = null;
            dt = this.GetDataSet(FullPath, excelFileExtension).Tables[0];
            if (dt.Rows.Count <= 1) {
                PageUtility.ShowModelDlg(this.Page, "�ļ���û���κμ�¼��������ѡ��");
                return;
            }
            CustomerTableAdapter TACustomer = new CustomerTableAdapter();
            ImportLogTableAdapter TAImportLog = new ImportLogTableAdapter();
            ImportLogDetailTableAdapter TAImportLogDetail = new ImportLogDetailTableAdapter();
            MasterDataBLL mdBLL = new MasterDataBLL();

            transaction = TableAdapterHelper.BeginTransaction(TACustomer);
            TableAdapterHelper.SetTransaction(TAImportLog, transaction);
            TableAdapterHelper.SetTransaction(TAImportLogDetail, transaction);
            //�洢log��Ϣ
            ImportDS.ImportLogDataTable logTable = new ImportDS.ImportLogDataTable();
            ImportDS.ImportLogRow logRow = logTable.NewImportLogRow();

            int stuffUserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
            string fullname = this.fileUpLoad.PostedFile.FileName.ToString();
            string tmpFile = fullname.Remove(0, fullname.LastIndexOf("\\") + 1);
            logRow.FileName = tmpFile;
            logRow.ImportDate = DateTime.Now;
            logRow.ImportUserID = stuffUserID;
            logRow.ImportType = 3;
            logRow.TotalCount = dt.Rows.Count - 1;
            logRow.SuccessCount = dt.Rows.Count - 1;
            logRow.FailCount = 0;
            logTable.AddImportLogRow(logRow);
            TAImportLog.Update(logTable);

            //����ÿ����ϸ
            ERS.CustomerDataTable tbCustomer = new ERS.CustomerDataTable();
            ImportDS.ImportLogDetailDataTable ImportLogDetailTable = new ImportDS.ImportLogDetailDataTable();
            int row_count = dt.Rows.Count;
            string errorInfor = string.Empty;
            //  int expenseTypeID = int.Parse(ExpenseTypeDDL.SelectedValue);
            //��ʼ����ÿ����ϸ
            for (int i = 1; i <= row_count - 1; i++) {
                if (CheckData(dt.Rows[i]) != null) {
                    errorInfor = "��" + (i + 1) + "����" + CheckData(dt.Rows[i]);
                    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    ImportDetailRow.LogID = logRow.LogID;
                    ImportDetailRow.Line = i + 1;
                    ImportDetailRow.Error = errorInfor;
                    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    logRow.FailCount = logRow.FailCount + 1;
                    logRow.SuccessCount = logRow.SuccessCount - 1;
                    TAImportLog.Update(logRow);
                    continue;
                } else {
                    DataRow row = dt.Rows[i];
                    string CustomerNo = row[0].ToString().Trim();
                    string CustomerName = row[1].ToString().Trim();
                    string ProvinceName = row[2].ToString().Trim();
                    string CityName = row[3].ToString().Trim();
                    string CustomerTypeName = row[4].ToString().Trim();
                    string ChannelTypeName = row[5].ToString().Trim();
                    string OUName = row[6].ToString().Trim();
                    string BudgetOUName = row[7].ToString().Trim();

                    ERS.CustomerDataTable tbCustomerTemp = mdBLL.GetCustomerByCustomerName(CustomerName);

                    if (tbCustomerTemp != null && tbCustomerTemp.Count > 0) {
                        errorInfor = "��" + (i + 1) + "���д���Ѵ��ڿͻ���" + CustomerName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    //ERS.ProvinceDataTable tbProvince = mdBLL.GetProvinceByProvinceName(ProvinceName);

                    //if (tbProvince == null || tbProvince.Count == 0) {
                    //    errorInfor = "��" + (i + 1) + "���д���Ҳ���ʡ�ݡ�" + ProvinceName + "��";
                    //    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    //    ImportDetailRow.LogID = logRow.LogID;
                    //    ImportDetailRow.Line = i + 1;
                    //    ImportDetailRow.Error = errorInfor;
                    //    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    //    logRow.FailCount = logRow.FailCount + 1;
                    //    logRow.SuccessCount = logRow.SuccessCount - 1;
                    //    TAImportLog.Update(logRow);
                    //    continue;
                    //}

                    ERS.CityDataTable tbCity = mdBLL.GetCityByCityName(CityName);

                    if (tbCity == null || tbCity.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д���Ҳ������С�" + CityName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.CustomerTypeDataTable tbCustomerType = mdBLL.GetCustomerTypeByCustomerTypeName(CustomerTypeName);

                    if (tbCustomerType == null || tbCustomerType.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д���Ҳ����ͻ����͡�" + CustomerTypeName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.ChannelTypeDataTable tbChannelType = mdBLL.GetChannelTypeByChannelTypeName(ChannelTypeName);

                    if (tbChannelType == null || tbChannelType.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д���Ҳ����ͻ�������" + ChannelTypeName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    AuthorizationDS.OrganizationUnitDataTable ouTable = new OUTreeBLL().GetDataByOrganizationUnitName(OUName);

                    if (ouTable == null || ouTable.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д��ϵͳ���Ҳ����˲��š�" + OUName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    if (ouTable.Count > 1) {
                        errorInfor = "��" + (i + 1) + "���д��ϵͳ���ҵ���������ƵIJ��š�" + OUName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    AuthorizationDS.OrganizationUnitDataTable BudgetOUTable = new OUTreeBLL().GetDataByOrganizationUnitName(BudgetOUName);

                    if (BudgetOUTable == null || BudgetOUTable.Count == 0) {
                        errorInfor = "��" + (i + 1) + "���д��ϵͳ���Ҳ����˲��š�" + BudgetOUName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    if (BudgetOUTable.Count > 1) {
                        errorInfor = "��" + (i + 1) + "���д��ϵͳ���ҵ���������ƵIJ��š�" + BudgetOUName + "��";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.CustomerRow rowCustomer = tbCustomer.NewCustomerRow();

                    rowCustomer.CustomerNo = CustomerNo;
                    rowCustomer.CustomerName = CustomerName;
                    rowCustomer.CityID = tbCity[0].CityID;
                    rowCustomer.CustomerTypeID = tbCustomerType[0].CustomerTypeID;
                    rowCustomer.ChannelTypeID = tbChannelType[0].ChannelTypeID;
                    rowCustomer.OrganizationUnitID = ouTable[0].OrganizationUnitId;
                    rowCustomer.ApplyOrganizationUnitID = BudgetOUTable[0].OrganizationUnitId;
                    rowCustomer.IsActive = true;

                    tbCustomer.AddCustomerRow(rowCustomer);
                    TACustomer.Update(rowCustomer);
                }
            }
            TAImportLog.Update(logRow);
            TAImportLogDetail.Update(ImportLogDetailTable);
            transaction.Commit();
            string returnString = "�ɹ�����" + logRow.SuccessCount.ToString() + "����Ϣ";
            PageUtility.ShowModelDlg(this.Page, returnString);
        } catch (Exception ex) {
            if (transaction != null) {
                transaction.Rollback();
            } PageUtility.ShowModelDlg(this.Page, "Save Fail!" + ex.ToString());
        } finally {
            if (transaction != null) {
                transaction.Dispose();
            }
        }
    }
Exemple #6
0
    public void SaveDataToDB(string FullPath, string FileName, string excelFileExtension)
    {
        SqlTransaction transaction = null;

        try {
            DataTable dt = null;
            dt = this.GetDataSet(FullPath, excelFileExtension).Tables[0];
            if (dt.Rows.Count <= 1)
            {
                PageUtility.ShowModelDlg(this.Page, "文件中没有任何记录,请重新选择");
                return;
            }
            CustomerTableAdapter        TACustomer        = new CustomerTableAdapter();
            ImportLogTableAdapter       TAImportLog       = new ImportLogTableAdapter();
            ImportLogDetailTableAdapter TAImportLogDetail = new ImportLogDetailTableAdapter();
            MasterDataBLL mdBLL = new MasterDataBLL();

            transaction = TableAdapterHelper.BeginTransaction(TACustomer);
            TableAdapterHelper.SetTransaction(TAImportLog, transaction);
            TableAdapterHelper.SetTransaction(TAImportLogDetail, transaction);
            //存储log信息
            ImportDS.ImportLogDataTable logTable = new ImportDS.ImportLogDataTable();
            ImportDS.ImportLogRow       logRow   = logTable.NewImportLogRow();

            int    stuffUserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
            string fullname    = this.fileUpLoad.PostedFile.FileName.ToString();
            string tmpFile     = fullname.Remove(0, fullname.LastIndexOf("\\") + 1);
            logRow.FileName     = tmpFile;
            logRow.ImportDate   = DateTime.Now;
            logRow.ImportUserID = stuffUserID;
            logRow.ImportType   = 3;
            logRow.TotalCount   = dt.Rows.Count - 1;
            logRow.SuccessCount = dt.Rows.Count - 1;
            logRow.FailCount    = 0;
            logTable.AddImportLogRow(logRow);
            TAImportLog.Update(logTable);

            //处理每条明细
            ERS.CustomerDataTable             tbCustomer           = new ERS.CustomerDataTable();
            ImportDS.ImportLogDetailDataTable ImportLogDetailTable = new ImportDS.ImportLogDetailDataTable();
            int    row_count  = dt.Rows.Count;
            string errorInfor = string.Empty;
            //  int expenseTypeID = int.Parse(ExpenseTypeDDL.SelectedValue);
            //开始处理每条明细
            for (int i = 1; i <= row_count - 1; i++)
            {
                if (CheckData(dt.Rows[i]) != null)
                {
                    errorInfor = "第" + (i + 1) + "行有错:" + CheckData(dt.Rows[i]);
                    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    ImportDetailRow.LogID = logRow.LogID;
                    ImportDetailRow.Line  = i + 1;
                    ImportDetailRow.Error = errorInfor;
                    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    logRow.FailCount    = logRow.FailCount + 1;
                    logRow.SuccessCount = logRow.SuccessCount - 1;
                    TAImportLog.Update(logRow);
                    continue;
                }
                else
                {
                    DataRow row              = dt.Rows[i];
                    string  CustomerNo       = row[0].ToString().Trim();
                    string  CustomerName     = row[1].ToString().Trim();
                    string  ProvinceName     = row[2].ToString().Trim();
                    string  CityName         = row[3].ToString().Trim();
                    string  CustomerTypeName = row[4].ToString().Trim();
                    string  ChannelTypeName  = row[5].ToString().Trim();
                    string  OUName           = row[6].ToString().Trim();
                    string  BudgetOUName     = row[7].ToString().Trim();

                    ERS.CustomerDataTable tbCustomerTemp = mdBLL.GetCustomerByCustomerName(CustomerName);

                    if (tbCustomerTemp != null && tbCustomerTemp.Count > 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:已存在客户《" + CustomerName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    //ERS.ProvinceDataTable tbProvince = mdBLL.GetProvinceByProvinceName(ProvinceName);

                    //if (tbProvince == null || tbProvince.Count == 0) {
                    //    errorInfor = "第" + (i + 1) + "行有错:找不到省份《" + ProvinceName + "》";
                    //    ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                    //    ImportDetailRow.LogID = logRow.LogID;
                    //    ImportDetailRow.Line = i + 1;
                    //    ImportDetailRow.Error = errorInfor;
                    //    ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                    //    logRow.FailCount = logRow.FailCount + 1;
                    //    logRow.SuccessCount = logRow.SuccessCount - 1;
                    //    TAImportLog.Update(logRow);
                    //    continue;
                    //}

                    ERS.CityDataTable tbCity = mdBLL.GetCityByCityName(CityName);

                    if (tbCity == null || tbCity.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:找不到城市《" + CityName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.CustomerTypeDataTable tbCustomerType = mdBLL.GetCustomerTypeByCustomerTypeName(CustomerTypeName);

                    if (tbCustomerType == null || tbCustomerType.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:找不到客户类型《" + CustomerTypeName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.ChannelTypeDataTable tbChannelType = mdBLL.GetChannelTypeByChannelTypeName(ChannelTypeName);

                    if (tbChannelType == null || tbChannelType.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:找不到客户渠道《" + ChannelTypeName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    AuthorizationDS.OrganizationUnitDataTable ouTable = new OUTreeBLL().GetDataByOrganizationUnitName(OUName);

                    if (ouTable == null || ouTable.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:系统中找不到此部门《" + OUName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    if (ouTable.Count > 1)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:系统中找到多个此名称的部门《" + OUName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    AuthorizationDS.OrganizationUnitDataTable BudgetOUTable = new OUTreeBLL().GetDataByOrganizationUnitName(BudgetOUName);

                    if (BudgetOUTable == null || BudgetOUTable.Count == 0)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:系统中找不到此部门《" + BudgetOUName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    if (BudgetOUTable.Count > 1)
                    {
                        errorInfor = "第" + (i + 1) + "行有错:系统中找到多个此名称的部门《" + BudgetOUName + "》";
                        ImportDS.ImportLogDetailRow ImportDetailRow = ImportLogDetailTable.NewImportLogDetailRow();
                        ImportDetailRow.LogID = logRow.LogID;
                        ImportDetailRow.Line  = i + 1;
                        ImportDetailRow.Error = errorInfor;
                        ImportLogDetailTable.AddImportLogDetailRow(ImportDetailRow);
                        logRow.FailCount    = logRow.FailCount + 1;
                        logRow.SuccessCount = logRow.SuccessCount - 1;
                        TAImportLog.Update(logRow);
                        continue;
                    }

                    ERS.CustomerRow rowCustomer = tbCustomer.NewCustomerRow();

                    rowCustomer.CustomerNo              = CustomerNo;
                    rowCustomer.CustomerName            = CustomerName;
                    rowCustomer.CityID                  = tbCity[0].CityID;
                    rowCustomer.CustomerTypeID          = tbCustomerType[0].CustomerTypeID;
                    rowCustomer.ChannelTypeID           = tbChannelType[0].ChannelTypeID;
                    rowCustomer.OrganizationUnitID      = ouTable[0].OrganizationUnitId;
                    rowCustomer.ApplyOrganizationUnitID = BudgetOUTable[0].OrganizationUnitId;
                    rowCustomer.IsActive                = true;

                    tbCustomer.AddCustomerRow(rowCustomer);
                    TACustomer.Update(rowCustomer);
                }
            }
            TAImportLog.Update(logRow);
            TAImportLogDetail.Update(ImportLogDetailTable);
            transaction.Commit();
            string returnString = "成功导入" + logRow.SuccessCount.ToString() + "条信息";
            PageUtility.ShowModelDlg(this.Page, returnString);
        } catch (Exception ex) {
            if (transaction != null)
            {
                transaction.Rollback();
            }
            PageUtility.ShowModelDlg(this.Page, "Save Fail!" + ex.ToString());
        } finally {
            if (transaction != null)
            {
                transaction.Dispose();
            }
        }
    }