Exemplo n.º 1
0
        /// <summary>
        /// 选择货品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonEditProduct_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Invoices.ChooseProductForm f = new Book.UI.Invoices.ChooseProductForm();
            if (f.ShowDialog(this) == DialogResult.OK)
            {
                Model.Product product = f.SelectedItem as Model.Product;
                if (product != null)
                {
                    this.buttonEditProduct.Text   = product.Id;
                    this.textEditProductName.Text = string.IsNullOrEmpty(product.CustomerProductName) ? product.ProductName : product.ProductName + "{" + product.CustomerProductName + "}";

                    if (!string.IsNullOrEmpty(product.CustomerProductName))
                    {
                        this.textEditCustomerPro.Text = product.CustomerProductName;
                    }

                    if (product.IsCustomerProduct == true && !string.IsNullOrEmpty(product.CustomerProductName))
                    {
                        this._bomParentPartInfo = bomParentPartInfo.Get(this.productManager.Get(product.CustomerBeforeProductId));
                        // this.textEditCustomProduct.Text = product.CustomerProductName;
                        this.newChooseContorlCustomer.EditValue = product.Customer;
                    }
                    else
                    {
                        this._bomParentPartInfo = bomParentPartInfo.Get(product);
                        // this.textEditCustomProduct.Text = "";
                        this.newChooseContorlCustomer.EditValue = null;
                    }
                    this._manprocedure.Bom = this._bomParentPartInfo;
                    if (this._bomParentPartInfo != null)
                    {
                        this.textEditBOMID.EditValue = this._bomParentPartInfo.Id;
                        // this.textEditBOMType.EditValue = this._bomParentPartInfo.MaterialType;
                    }
                }
            }
            f.Dispose();
            GC.Collect();
        }
Exemplo n.º 2
0
        private void GetBomComponetByParent(Model.BomComponentInfo componet, List <Model.BomComponentInfo> _comDetailss)
        {
            Model.BomParentPartInfo _bomparent = bomParentPartInfoManager.Get(componet.Product);
            if (_bomparent != null)
            {
                IList <Model.BomComponentInfo> comList = this.bomComponentInfoManager.SelectSimpleForHandBook(_bomparent);
                if (comList != null && comList.Count > 0)
                {
                    foreach (var item in comList)
                    {
                        //商品类型为:自制或者外购 才会带出,其他一律不需要
                        //if (item.Product.IsProcee == false && item.Product.TrustOut == false && (item.Product.HomeMade == true || item.Product.OutSourcing == true))
                        //{
                        //item.UseQuantity = componet.UseQuantity * item.UseQuantity * (1 + (item.SubLoseRate.HasValue ? item.SubLoseRate.Value * 0.01 : 0));
                        item.UseQuantity = componet.UseQuantity * item.UseQuantity;
                        _comDetailss.Add(item);
                        //}

                        //递归调用
                        GetBomComponetByParent(item, _comDetailss);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void bar_ExportSelectProduct_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Type objClassType = null;

            objClassType = Type.GetTypeFromProgID("Excel.Application");
            if (objClassType == null)
            {
                MessageBox.Show("本機沒有安裝Excel", "提示!", MessageBoxButtons.OK);
                return;
            }

            IList <Model.BomParentPartInfo> parentList = ((System.Windows.Forms.BindingSource)(this.gridControl1.DataSource)).DataSource as IList <Model.BomParentPartInfo>;

            if (parentList != null && parentList.Count > 0)
            {
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                excel.Application.Workbooks.Add(true);
                Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)excel.Worksheets[1];

                #region SetHeader
                sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 10]).RowHeight           = 20;
                sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 10]).Font.Size           = 15;
                sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 10]).HorizontalAlignment = -4108;
                sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 10]).ColumnWidth         = 12;
                sheet.get_Range(excel.Cells[1, 3], excel.Cells[1, 3]).ColumnWidth          = 50;

                sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 10]).Interior.Color = 12566463;

                //excel.get_Range(excel.Cells[2, 1], excel.Cells[details.Count + 2, 20]).RowHeight = 20;
                //excel.get_Range(excel.Cells[2, 1], excel.Cells[details.Count + 2, 20]).Font.Size = 13;
                //excel.get_Range(excel.Cells[3, 1], excel.Cells[details.Count + 2, 20]).WrapText = true;
                //excel.get_Range(excel.Cells[3, 1], excel.Cells[details.Count + 2, 20]).EntireRow.AutoFit();

                sheet.Cells[1, 1]  = "级别";
                sheet.Cells[1, 2]  = "子件编号";
                sheet.Cells[1, 3]  = "子件名称";
                sheet.Cells[1, 4]  = "客户型号";
                sheet.Cells[1, 5]  = "计量单位";
                sheet.Cells[1, 6]  = "使用数量";
                sheet.Cells[1, 7]  = "损耗率";
                sheet.Cells[1, 8]  = "净重";
                sheet.Cells[1, 9]  = "生效日期";
                sheet.Cells[1, 10] = "失效日期";

                #endregion

                int row = 2;

                foreach (var model in parentList)
                {
                    if (model.IsChecked)
                    {
                        try
                        {
                            #region 每个商品一个Sheet
                            //Model.BomParentPartInfo _bomParmentPartInfo = bomParentPartInfoManager.Get(model.BomId);
                            //List<Model.BomComponentInfo> list = GetBomComponetList(_bomParmentPartInfo);

                            //if (sheet.Name != "Sheet1")
                            //{
                            //    excel.Worksheets.Add(Missing.Value, sheet, Missing.Value, Missing.Value);
                            //}
                            //sheet = ((Microsoft.Office.Interop.Excel.Worksheet)excel.Worksheets[excel.Worksheets.Count]);

                            //#region SetHeader
                            //sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 7]).RowHeight = 20;
                            //sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 7]).Font.Size = 15;
                            //sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 7]).HorizontalAlignment = -4108;
                            //sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 7]).ColumnWidth = 12;
                            //sheet.get_Range(excel.Cells[1, 2], excel.Cells[1, 2]).ColumnWidth = 50;

                            //sheet.get_Range(excel.Cells[1, 1], excel.Cells[1, 7]).Interior.Color = 12566463;

                            ////excel.get_Range(excel.Cells[2, 1], excel.Cells[details.Count + 2, 20]).RowHeight = 20;
                            ////excel.get_Range(excel.Cells[2, 1], excel.Cells[details.Count + 2, 20]).Font.Size = 13;
                            ////excel.get_Range(excel.Cells[3, 1], excel.Cells[details.Count + 2, 20]).WrapText = true;
                            ////excel.get_Range(excel.Cells[3, 1], excel.Cells[details.Count + 2, 20]).EntireRow.AutoFit();

                            //sheet.Cells[1, 1] = "级别";
                            //sheet.Cells[1, 2] = "子件名称";
                            //sheet.Cells[1, 3] = "计量单位";
                            //sheet.Cells[1, 4] = "使用数量";
                            //sheet.Cells[1, 5] = "损耗率";
                            //sheet.Cells[1, 6] = "生效日期";
                            //sheet.Cells[1, 7] = "失效日期";
                            ////sheet.Cells[1, 8] = "备注";

                            //#endregion

                            //try
                            //{
                            //    sheet.Name = list[0].Product.Id;
                            //}
                            //catch
                            //{
                            //    sheet.Name = list[0].Product.Id + "-" + list[0].Product.ProductVersion;
                            //}

                            //int row = 2;
                            //foreach (var item in list)
                            //{
                            //    sheet.Cells[row, 1] = item.Jibie;
                            //    sheet.Cells[row, 2] = item.Product.ProductName;
                            //    sheet.Cells[row, 3] = item.Unit;
                            //    sheet.Cells[row, 4] = item.UseQuantity;
                            //    sheet.Cells[row, 5] = item.SubLoseRate == null ? 0 : item.SubLoseRate;
                            //    sheet.Cells[row, 6] = Convert.ToDateTime(item.EffectsDate).ToString("yyyy-MM-dd");
                            //    sheet.Cells[row, 7] = Convert.ToDateTime(item.ExpiringDate).ToString("yyyy-MM-dd");
                            //    //RichTextBox rt = new RichTextBox();
                            //    //rt.Rtf = item.ProductDesc;
                            //    //rt.SelectAll();
                            //    //sheet.Cells[row, 8] = rt.SelectedText;

                            //    //不同级别不同颜色
                            //    switch (item.Jibie)
                            //    {
                            //        case 1:
                            //            sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 7]).Interior.Color = 13311;     //红
                            //            break;
                            //        case 2:
                            //            sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 7]).Interior.Color = 6750105;   //浅绿
                            //            break;
                            //        case 3:
                            //            sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 7]).Interior.Color = 16763955;  //浅蓝
                            //            break;
                            //        case 4:
                            //            sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 7]).Interior.Color = 6750207;   //浅黄
                            //            break;
                            //        case 5:
                            //            sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 7]).Interior.Color = 16711935;  //浅紫
                            //            break;
                            //        case 6:
                            //            sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 7]).Interior.Color = 12566463;  //浅灰
                            //            break;
                            //    }

                            //    row++;
                            //}
                            #endregion

                            #region 所有商品放一个Sheet

                            Model.BomParentPartInfo       _bomParmentPartInfo = bomParentPartInfoManager.Get(model.BomId);
                            List <Model.BomComponentInfo> list = GetBomComponetList(_bomParmentPartInfo);

                            foreach (var item in list)
                            {
                                sheet.Cells[row, 1]  = item.Jibie;
                                sheet.Cells[row, 2]  = item.Product.Id;
                                sheet.Cells[row, 3]  = item.Product.ProductName;
                                sheet.Cells[row, 4]  = item.Product.CustomerProductName;
                                sheet.Cells[row, 5]  = item.Unit;
                                sheet.Cells[row, 6]  = item.UseQuantity;
                                sheet.Cells[row, 7]  = item.SubLoseRate == null ? 0 : item.SubLoseRate;
                                sheet.Cells[row, 8]  = item.Product.NetWeight.ToString();
                                sheet.Cells[row, 9]  = Convert.ToDateTime(item.EffectsDate).ToString("yyyy-MM-dd");
                                sheet.Cells[row, 10] = Convert.ToDateTime(item.ExpiringDate).ToString("yyyy-MM-dd");

                                if (item.Jibie == 0)
                                {
                                    sheet.get_Range(sheet.Cells[row, 1], sheet.Cells[row, 10]).Interior.Color = 13311;     //红
                                }
                                row++;
                            }
                            row++;
                            row++;

                            #endregion
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }

                excel.Visible = true;
            }
        }