Exemplo n.º 1
0
        private void btnSalesCode_Click(object sender, EventArgs e)
        {
            SalesCode SC         = new SalesCode();
            bool      isFormOpen = IsAlreadyOpen(typeof(SalesCode));

            if (isFormOpen == false)
            {
                SC.Show();
            }
        }
Exemplo n.º 2
0
        public CMCResponse UploadExcelFile()
        {
            try {
                //保存文件
                var    file     = System.Web.HttpContext.Current.Request.Files[0];
                string fullPath = HttpContext.Current.Server.MapPath("~/ExcelUpload/") + file.FileName;
                file.SaveAs(fullPath);

                //获取文件数据
                using (FileStream fs = new FileStream(fullPath, FileMode.Open))
                {
                    IWorkbook workbook     = new XSSFWorkbook(fs);
                    ISheet    sheet        = workbook.GetSheetAt(0);
                    int       lastRowIndex = sheet.LastRowNum;

                    //第一行获取活动名称
                    IRow   row          = sheet.GetRow(0);
                    int    rowLastIndex = row.LastCellNum - 1;
                    string activeName   = row.GetCell(rowLastIndex).StringCellValue;
                    int    lastColumn   = 0;
                    switch (activeName)
                    {
                    case "激活":
                        lastColumn = 9;

                        break;

                    case "营销":
                        lastColumn = 12;

                        break;

                    case "消费者":
                        lastColumn = 16;

                        break;

                    case "资产":
                        lastColumn = 18;

                        break;

                    case "资产领用":
                        lastColumn = 21;

                        break;

                    default:
                        Response.status  = 1;
                        Response.message = "上传活动名称有误";
                        return(Response);
                    }
                    //第3/4行获取名称基本信息
                    //List<string> nameList = new List<string>();
                    //List<string> basicInfo = new List<string>();
                    //for (int nameIndex = 0; nameIndex < lastColumn; nameIndex++)
                    //{
                    //    row = sheet.GetRow(2);
                    //    nameList.Add(row.GetCell(nameIndex).StringCellValue);
                    //}

                    //生成上传活动信息存入数据库
                    byte[] byteArray = new byte[file.ContentLength];
                    file.InputStream.Read(byteArray, 0, file.ContentLength);
                    //fs.Read(byteArray, 0, Convert.ToInt32(fs.Length));

                    IRow       row3       = sheet.GetRow(3);
                    CodeActive codeActive = new CodeActive();
                    codeActive.AppId           = "Excel文件上传";
                    codeActive.CorpCode        = row3.GetCell(5).StringCellValue;
                    codeActive.CorpName        = row3.GetCell(4).StringCellValue;
                    codeActive.SubCorpCode     = row3.GetCell(6).StringCellValue;
                    codeActive.ProductCode     = row3.GetCell(8).StringCellValue;
                    codeActive.ProductName     = row3.GetCell(7).StringCellValue;
                    codeActive.ProduceWorkline = row3.GetCell(6).StringCellValue;
                    codeActive.ActivityName    = activeName;
                    codeActive.Amount          = Convert.ToString(lastRowIndex - 2);
                    codeActive.ActualQuantity  = Convert.ToString(lastRowIndex - 2);
                    codeActive.UploadDate      = DateTime.Now;
                    codeActive.Uploader        = "CMC后台";
                    codeActive.ProcessType     = 3;
                    codeActive.Memo            = row3.GetCell(9).StringCellValue;
                    codeActive.ApplyId         = 0;

                    int activeID = CodeActiveUploadFactory.Instance.InsertNewActive(codeActive, byteArray);
                    if (activeName == "激活")
                    {
                        List <ActiveCode> alist = new List <ActiveCode>();
                        //第4行开始获取数据
                        for (int index = 3; index <= lastRowIndex; index++)
                        {
                            //获取当前行
                            row = sheet.GetRow(index);
                            //生成Mongo对象存码信息

                            ActiveCode c = new ActiveCode();
                            c.ActiveName     = activeName;
                            c.CreateDate     = row.GetCell(2).DateCellValue;;
                            c.ApplyId        = codeActive.ApplyId;
                            c.CodeActivityId = activeID;
                            c.CorpCode       = codeActive.CorpCode;
                            c.SubCorpCode    = codeActive.SubCorpCode;
                            c.CorpName       = codeActive.CorpName;
                            try
                            {
                                c.Code = row.GetCell(0).StringCellValue;
                            }
                            catch
                            {
                                c.Code = row.GetCell(0).NumericCellValue.ToString();
                            }
                            //c.MaskCode = row.GetCell(1).NumericCellValue.ToString();
                            c.ProductCode = row.GetCell(8).StringCellValue;
                            c.ProductName = row.GetCell(7).StringCellValue;
                            c.Memo        = row.GetCell(9).StringCellValue;
                            alist.Add(c);
                        }
                        string res = ReportFactory.Instance.SplitMongoInster <ActiveCode>(alist);
                        if (res == "数据插入MongoDB失败")
                        {
                            Response.status       = 0;
                            this.Response.message = res + ",检查MongoDB是否正常";
                            return(Response);
                        }
                    }
                    if (activeName == "营销")
                    {
                        List <SalesCode> alist = new List <SalesCode>();
                        //第4行开始获取数据
                        for (int index = 3; index <= lastRowIndex; index++)
                        {
                            //获取当前行
                            row = sheet.GetRow(index);
                            //生成Mongo对象存码信息

                            SalesCode c = new SalesCode();
                            c.ActiveName     = activeName;
                            c.CreateDate     = row.GetCell(2).DateCellValue;;
                            c.ApplyId        = codeActive.ApplyId;
                            c.CodeActivityId = activeID;
                            c.CorpCode       = codeActive.CorpCode;
                            c.SubCorpCode    = codeActive.SubCorpCode;
                            c.CorpName       = codeActive.CorpName;
                            try
                            {
                                c.Code = row.GetCell(0).StringCellValue;
                            }
                            catch
                            {
                                c.Code = row.GetCell(0).NumericCellValue.ToString();
                            }
                            //c.MaskCode = row.GetCell(1).NumericCellValue.ToString();
                            c.ProductCode       = row.GetCell(8).StringCellValue;
                            c.ProductName       = row.GetCell(7).StringCellValue;
                            c.Memo              = row.GetCell(9).StringCellValue;
                            c.ActiveDescription = row.GetCell(10).StringCellValue;
                            c.ActiveStartDate   = row.GetCell(11).DateCellValue;
                            c.ActiveEndDate     = row.GetCell(12).DateCellValue;
                            alist.Add(c);
                        }
                        string res = ReportFactory.Instance.SplitMongoInster <SalesCode>(alist);
                        if (res == "数据插入MongoDB失败")
                        {
                            Response.status       = 0;
                            this.Response.message = res + ",检查MongoDB是否正常";
                            return(Response);
                        }
                    }
                    if (activeName == "消费者")
                    {
                        List <CustomerCode> alist = new List <CustomerCode>();
                        //第4行开始获取数据
                        for (int index = 3; index <= lastRowIndex; index++)
                        {
                            //获取当前行
                            row = sheet.GetRow(index);
                            //生成Mongo对象存码信息

                            CustomerCode c = new CustomerCode();
                            c.ActiveName     = activeName;
                            c.CreateDate     = row.GetCell(2).DateCellValue;;
                            c.ApplyId        = codeActive.ApplyId;
                            c.CodeActivityId = activeID;
                            c.CorpCode       = codeActive.CorpCode;
                            c.SubCorpCode    = codeActive.SubCorpCode;
                            c.CorpName       = codeActive.CorpName;
                            try
                            {
                                c.Code = row.GetCell(0).StringCellValue;
                            }
                            catch
                            {
                                c.Code = row.GetCell(0).NumericCellValue.ToString();
                            }
                            //c.MaskCode = row.GetCell(1).NumericCellValue.ToString();
                            c.ProductCode       = row.GetCell(8).StringCellValue;
                            c.ProductName       = row.GetCell(7).StringCellValue;
                            c.Memo              = row.GetCell(9).StringCellValue;
                            c.ActiveDescription = row.GetCell(10).StringCellValue;
                            c.ActiveStartDate   = row.GetCell(11).DateCellValue;
                            c.ActiveEndDate     = row.GetCell(12).DateCellValue;
                            c.CustomerOpenID    = row.GetCell(13).StringCellValue;
                            c.CustomerTime      = row.GetCell(14).DateCellValue;
                            c.CustomerLocatio   = row.GetCell(15).StringCellValue;
                            c.WhatActive        = row.GetCell(16).StringCellValue;
                            alist.Add(c);
                        }
                        string res = ReportFactory.Instance.SplitMongoInster <CustomerCode>(alist);
                        if (res == "数据插入MongoDB失败")
                        {
                            Response.status       = 0;
                            this.Response.message = res + ",检查MongoDB是否正常";
                            return(Response);
                        }
                    }
                    if (activeName == "消费者")
                    {
                        List <CustomerCode> alist = new List <CustomerCode>();
                        //第4行开始获取数据
                        for (int index = 3; index <= lastRowIndex; index++)
                        {
                            //获取当前行
                            row = sheet.GetRow(index);
                            //生成Mongo对象存码信息

                            CustomerCode c = new CustomerCode();
                            c.ActiveName     = activeName;
                            c.CreateDate     = row.GetCell(2).DateCellValue;;
                            c.ApplyId        = codeActive.ApplyId;
                            c.CodeActivityId = activeID;
                            c.CorpCode       = codeActive.CorpCode;
                            c.SubCorpCode    = codeActive.SubCorpCode;
                            c.CorpName       = codeActive.CorpName;
                            c.Code           = row.GetCell(0).NumericCellValue.ToString();
                            //c.MaskCode = row.GetCell(1).NumericCellValue.ToString();
                            c.ProductCode       = row.GetCell(8).StringCellValue;
                            c.ProductName       = row.GetCell(7).StringCellValue;
                            c.Memo              = row.GetCell(9).StringCellValue;
                            c.ActiveDescription = row.GetCell(10).StringCellValue;
                            c.ActiveStartDate   = row.GetCell(11).DateCellValue;
                            c.ActiveEndDate     = row.GetCell(12).DateCellValue;
                            c.CustomerOpenID    = row.GetCell(13).StringCellValue;
                            c.CustomerTime      = row.GetCell(14).DateCellValue;
                            c.CustomerLocatio   = row.GetCell(15).StringCellValue;
                            c.WhatActive        = row.GetCell(16).StringCellValue;
                            alist.Add(c);
                        }
                        string res = ReportFactory.Instance.SplitMongoInster <CustomerCode>(alist);
                        if (res == "数据插入MongoDB失败")
                        {
                            Response.status       = 0;
                            this.Response.message = res + ",检查MongoDB是否正常";
                            return(Response);
                        }
                    }
                    if (activeName == "资产")
                    {
                        List <PropertyCode> alist = new List <PropertyCode>();
                        //第4行开始获取数据
                        for (int index = 3; index <= lastRowIndex; index++)
                        {
                            //获取当前行
                            row = sheet.GetRow(index);
                            //生成Mongo对象存码信息

                            PropertyCode c = new PropertyCode();
                            c.ActiveName     = activeName;
                            c.CreateDate     = row.GetCell(2).DateCellValue;
                            c.ApplyId        = codeActive.ApplyId;
                            c.CodeActivityId = activeID;
                            c.CorpCode       = codeActive.CorpCode;
                            c.SubCorpCode    = codeActive.SubCorpCode;
                            c.CorpName       = codeActive.CorpName;
                            try
                            {
                                c.Code = row.GetCell(0).StringCellValue;
                            }
                            catch
                            {
                                c.Code = row.GetCell(0).NumericCellValue.ToString();
                            }
                            //c.MaskCode = row.GetCell(1).NumericCellValue.ToString();
                            c.ProductCode         = row.GetCell(8).StringCellValue;
                            c.ProductName         = row.GetCell(7).StringCellValue;
                            c.Memo                = row.GetCell(9).StringCellValue;
                            c.ProductProvider     = row.GetCell(17).StringCellValue;
                            c.ProductPurcheseDate = row.GetCell(18).DateCellValue;
                            alist.Add(c);
                        }
                        string res = ReportFactory.Instance.SplitMongoInster <PropertyCode>(alist);
                        if (res == "数据插入MongoDB失败")
                        {
                            Response.status       = 0;
                            this.Response.message = res + ",检查MongoDB是否正常";
                            return(Response);
                        }
                    }
                    if (activeName == "资产领用")
                    {
                        List <PropertyUseCode> alist = new List <PropertyUseCode>();
                        //第4行开始获取数据
                        for (int index = 3; index <= lastRowIndex; index++)
                        {
                            //获取当前行
                            row = sheet.GetRow(index);
                            //生成Mongo对象存码信息

                            PropertyUseCode c = new PropertyUseCode();
                            c.ActiveName     = activeName;
                            c.CreateDate     = row.GetCell(2).DateCellValue;
                            c.ApplyId        = codeActive.ApplyId;
                            c.CodeActivityId = activeID;
                            c.CorpCode       = codeActive.CorpCode;
                            c.SubCorpCode    = codeActive.SubCorpCode;
                            c.CorpName       = codeActive.CorpName;
                            try
                            {
                                c.Code = row.GetCell(0).StringCellValue;
                            }
                            catch
                            {
                                c.Code = row.GetCell(0).NumericCellValue.ToString();
                            }
                            //c.MaskCode = row.GetCell(1).NumericCellValue.ToString();
                            c.ProductCode     = row.GetCell(8).StringCellValue;
                            c.ProductName     = row.GetCell(7).StringCellValue;
                            c.Memo            = row.GetCell(9).StringCellValue;
                            c.ClaimDepartment = row.GetCell(19).StringCellValue;
                            c.ClaimPerson     = row.GetCell(20).StringCellValue;
                            c.ClaimDate       = row.GetCell(21).DateCellValue;
                            alist.Add(c);
                        }
                        string res = ReportFactory.Instance.SplitMongoInster <PropertyUseCode>(alist);
                        if (res == "数据插入MongoDB失败")
                        {
                            Response.status       = 0;
                            this.Response.message = res + ",检查MongoDB是否正常";
                            return(Response);
                        }
                    }
                }

                //删除文件
                System.IO.File.Delete(fullPath);

                Response.status  = 1;
                Response.message = "上传成功";
            }
            catch (Exception e)
            {
                Response.status  = 0;
                Response.message = e.Message;
            }

            return(Response);
        }