示例#1
0
        private void barIn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ExcelClass.ExcelClass1 ec = new Book.UI.ExcelClass.ExcelClass1();
                ec.Open(openFileDialog1.FileName);

                try
                {
                    BL.V.BeginTransaction();
                    Model.BGHandbookRange bGHandbookRange = null;
                    this.action = "insert";

                    Model.BGHandbookRangeDetail detail = null;
                    for (int i = 1; i <= ec.wb.Worksheets.Count; i++)
                    {
                        bGHandbookRange = new Book.Model.BGHandbookRange();
                        bGHandbookRange.DetailProducts      = new List <Model.BGHandbookRangeDetail>();
                        bGHandbookRange.DetailMaterials     = new List <Model.BGHandbookRangeDetail>();
                        bGHandbookRange.BGHandbookRangeId   = Guid.NewGuid().ToString();
                        bGHandbookRange.BGHandbookRangeDate = DateTime.Now;
                        Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)ec.wb.Worksheets[i];
                        bGHandbookRange.CompanyNameAndId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[3, 1]).Text.ToString().Substring(((Microsoft.Office.Interop.Excel.Range)ws.Cells[3, 1]).Text.ToString().IndexOf(':') + 1);

                        if (openFileDialog1.FileName.Contains("成品"))
                        {
                            //if (ws.Name != "草稿")
                            //{
                            for (int j = 6; j < 10000; j++)
                            {
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "经办关员意见:" || (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "" && ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() == ""))
                                {
                                    break;
                                }
                                detail = new Book.Model.BGHandbookRangeDetail();
                                detail.BGHandbookRangeDetailId = Guid.NewGuid().ToString();
                                detail.BGHandbookRangeId       = bGHandbookRange.BGHandbookRangeId;
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() != "")
                                {
                                    detail.Id = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString();
                                }
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() != "")
                                {
                                    detail.ProductName = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString();
                                }
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString() != "")
                                {
                                    detail.ProductSpecification = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString();
                                }
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 4]).Text.ToString() != "")
                                {
                                    detail.ProductUnit = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 4]).Text.ToString();
                                }
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString() != "")
                                {
                                    detail.CompanyProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString();
                                }
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString() != "")
                                {
                                    detail.CustomProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString();
                                }
                                if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString() != "")
                                {
                                    detail.Note = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString();
                                }

                                detail.ProductType = "成品";
                                bGHandbookRange.DetailProducts.Add(detail);
                            }
                            //}
                            //else
                            //{
                            //    for (int j = 6; j < 10000; j++)
                            //    {
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "经办关员意见:" || (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "" && ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() == ""))
                            //        {
                            //            break;
                            //        }
                            //        detail = new Book.Model.BGHandbookRangeDetail();
                            //        detail.BGHandbookRangeDetailId = Guid.NewGuid().ToString();
                            //        detail.BGHandbookRangeId = bGHandbookRange.BGHandbookRangeId;
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() != "")
                            //            detail.Id = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString();

                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() != "")
                            //            detail.CustomId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString();

                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString() != "")
                            //            detail.ProductName = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString();
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 4]).Text.ToString() != "")
                            //            detail.ProductSpecification = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 4]).Text.ToString();
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString() != "")
                            //            detail.ProductUnit = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString();
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString() != "")
                            //            detail.CompanyProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString();
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString() != "")
                            //            detail.CustomProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString();
                            //        if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 8]).Text.ToString() != "")
                            //            detail.Note = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 8]).Text.ToString();

                            //        detail.ProductType = "成品";
                            //        bGHandbookRange.DetailProducts.Add(detail);
                            //    }
                            //}
                        }

                        else if (openFileDialog1.FileName.Contains("料件"))
                        {
                            if (ws.Name == "Sheet4")
                            {
                                continue;
                            }
                            else if (ws.Name == "申报要素")
                            {
                                continue;
                            }
                            else
                            {
                                for (int j = 6; j < 10000; j++)
                                {
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "经办关员意见:" || (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "" && ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() == ""))
                                    {
                                        break;
                                    }
                                    detail = new Book.Model.BGHandbookRangeDetail();
                                    detail.BGHandbookRangeDetailId = Guid.NewGuid().ToString();
                                    detail.BGHandbookRangeId       = bGHandbookRange.BGHandbookRangeId;
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() != "")
                                    {
                                        detail.Id = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() != "")
                                    {
                                        detail.ProductName = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString() != "")
                                    {
                                        detail.ProductSpecification = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 4]).Text.ToString() != "")
                                    {
                                        detail.ProductUnit = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 4]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString() != "")
                                    {
                                        detail.CompanyProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString() != "")
                                    {
                                        detail.CustomProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString() != "")
                                    {
                                        detail.Note = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString();
                                    }

                                    detail.ProductType = "料件";
                                    bGHandbookRange.DetailMaterials.Add(detail);
                                }
                            }
                        }

                        bGHandbookRange.EmployeeId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[4, 1]).Text.ToString().Substring(((Microsoft.Office.Interop.Excel.Range)ws.Cells[4, 1]).Text.ToString().IndexOf(":") + 1, 4).Trim();
                        bGHandbookRange.Tel        = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[4, 1]).Text.ToString().Trim().Substring(((Microsoft.Office.Interop.Excel.Range)ws.Cells[4, 1]).Text.ToString().Trim().Length - 11);
                        this._manager.Insert(bGHandbookRange);
                    }
                    BL.V.CommitTransaction();
                    //this.bindingSourceProduct.DataSource = bGHandbookRange.DetailProducts;
                    //this.bindingSourceMaterial.DataSource = bGHandbookRange.DetailMaterials;
                    //this.gridControl1.RefreshDataSource();
                    //this.gridControl2.RefreshDataSource();
                    this.MoveLast();
                    this.action = "view";
                    this.Refresh();
                }
                catch
                {
                    BL.V.RollbackTransaction();
                    ec.Close();
                    throw;
                }
                ec.Close();
            }
        }
示例#2
0
        private void barIn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ExcelClass.ExcelClass1 ec = new Book.UI.ExcelClass.ExcelClass1();
                ec.Open(openFileDialog1.FileName);

                try
                {
                    BL.V.BeginTransaction();
                    Model.BGHandbookRange bGHandbookRange = null;
                    this.action = "insert";

                    Model.BGHandbookRangeDetail detail;
                    for (int i = 1; i < ec.wb.Worksheets.Count; i++)
                    {
                        bGHandbookRange                     = new Book.Model.BGHandbookRange();
                        bGHandbookRange.Details             = new List <Model.BGHandbookRangeDetail>();
                        bGHandbookRange.BGHandbookRangeId   = Guid.NewGuid().ToString();
                        bGHandbookRange.BGHandbookRangeDate = DateTime.Now;
                        Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)ec.wb.Worksheets[i];
                        bGHandbookRange.CompanyNameAndId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[3, 1]).Text.ToString().Substring(((Microsoft.Office.Interop.Excel.Range)ws.Cells[3, 1]).Text.ToString().IndexOf(':') + 1);

                        if (openFileDialog1.FileName.Contains("成品"))
                        {
                            this.cobProductType.EditValue = "成品";
                            if (ws.Name != "草稿")
                            {
                                for (int j = 6; j < 200; j++)
                                {
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "经办关员意见:" || (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() == "" && ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() == ""))
                                    {
                                        break;
                                    }
                                    detail = new Book.Model.BGHandbookRangeDetail();
                                    detail.BGHandbookRangeDetailId = Guid.NewGuid().ToString();
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString() != "")
                                    {
                                        detail.Id = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 1]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString() != "")
                                    {
                                        detail.ProductName = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 2]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString() != "")
                                    {
                                        detail.ProductSpecification = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 3]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString() != "")
                                    {
                                        detail.ProductUnit = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 5]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString() != "")
                                    {
                                        detail.CompanyProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 6]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString() != "")
                                    {
                                        detail.CustomProductId = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 7]).Text.ToString();
                                    }
                                    if (((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 9]).Text.ToString() != "")
                                    {
                                        detail.Note = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[j, 9]).Text.ToString();
                                    }
                                }
                            }
                        }

                        else if (openFileDialog1.FileName.Contains("料件"))
                        {
                            this.cobProductType.EditValue = "料件";
                        }


                        bGHandbookRange.Employee   = (new BL.EmployeeManager()).GetByOperatorName(((Microsoft.Office.Interop.Excel.Range)ws.Cells[4, 1]).Text.ToString().Substring(((Microsoft.Office.Interop.Excel.Range)ws.Cells[4, 1]).Text.ToString().IndexOf(':') + 1, 4).Trim());
                        bGHandbookRange.EmployeeId = bGHandbookRange.Employee.EmployeeId;
                    }
                }
                catch
                {
                    BL.V.RollbackTransaction();
                    ec.Close();
                    throw;
                }
                ec.Close();
            }
        }