public void ImportToAccess()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DataSet ds      = new DataSet();
                string  strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ofd.FileName + ";" +
                                  "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                string           strExcel  = "";
                OleDbDataAdapter myCommand = null;
                strExcel  = string.Format("select * from [{0}$]", "Sheet1"); //Sheet1为excel中工作薄
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                myCommand.Fill(ds, "Sheet1");
                DataTable dt = ds.Tables["Sheet1"];

                Encoding gb2312 = Encoding.GetEncoding("GB2312");
                for (int iRow = 1; iRow < dt.Rows.Count; iRow++)
                {
                    BaseInfoMaterial bim = BaseInfoMaterial.New;
                    bim.Code             = dt.Rows[iRow][0].ToString();
                    bim.Name             = dt.Rows[iRow][1].ToString();
                    bim.ShortCode        = PinYinTransfer.GetInitials(bim.Name, gb2312);
                    bim.Barcode          = bim.ShortCode;
                    bim.Category         = dt.Rows[iRow][4].ToString();
                    bim.Specification    = dt.Rows[iRow][5].ToString();
                    bim.ItemNo           = dt.Rows[iRow][6].ToString();
                    bim.Brand            = dt.Rows[iRow][7].ToString();
                    bim.PurchaseUnitName = dt.Rows[iRow][8].ToString();
                    bim.SaleUnitName     = dt.Rows[iRow][9].ToString();
                    bim.UnitConvValue    = decimal.Parse(dt.Rows[iRow][10].ToString());
                    bim.UnitPrice        = decimal.Parse(dt.Rows[iRow][11].ToString());
                    if (bim.UnitPrice == 0)
                    {
                        bim.ConvPrice = 0;
                    }
                    else
                    {
                        bim.ConvPrice = bim.UnitPrice / bim.UnitConvValue;
                    }
                    bim.AvgPrice         = bim.ConvPrice;
                    bim.RetailPrice      = decimal.Parse(dt.Rows[iRow][14].ToString());
                    bim.MemberPrice      = decimal.Parse(dt.Rows[iRow][15].ToString());
                    bim.InvQuantity      = decimal.Parse(dt.Rows[iRow][16].ToString());
                    bim.ConvQuantity     = bim.InvQuantity * bim.UnitConvValue;
                    bim.InventoryCost    = bim.ConvPrice * bim.ConvQuantity;
                    bim.StockLowAlarm    = decimal.Parse(dt.Rows[iRow][19].ToString());
                    bim.BonusPoint       = decimal.Parse(dt.Rows[iRow][20].ToString());
                    bim.IsAddToInventory = (bool)dt.Rows[iRow][21];
                    bim.IsIngredient     = (bool)dt.Rows[iRow][22];
                    bim.Status           = dt.Rows[iRow][23].ToString();
                    bim.Remark           = dt.Rows[iRow][24].ToString();
                    bim.OptrType         = UserStatics.OptrType;
                    bim.SavedOn          = DateTime.Now;
                    bim.Save();
                }
            }
        }
Example #2
0
        private void tbSelectItem_KeyDown(object sender, KeyEventArgs e)
        {
            //选好单品,并且回车
            if (e.KeyCode == Keys.Enter && tbSelectItem.Text != "")
            {
                SupplyChainPos       scp  = SupplyChainPos.FindById(PosId);
                SupplyChainPosDetail scpd = SupplyChainPosDetail.New;
                BaseInfoMaterial     bim  = BaseInfoMaterial.FindById(MaterialId);
                scpd.IsPaid           = false;
                scpd.MaterialId       = bim.Id;
                scpd.MaterialName     = bim.Name;
                scpd.MaterialCategory = bim.Category;
                scpd.UnitName         = bim.SaleUnitName;
                if (scp.MemberId != 0)
                {
                    scpd.UnitPrice = bim.MemberPrice;
                }
                else
                {
                    scpd.UnitPrice = bim.RetailPrice;
                }
                scpd.Quantity      = 1;
                scpd.Discount      = 0;
                scpd.Amount        = scpd.UnitPrice * scpd.Quantity;
                scpd.IsReturns     = false;
                scpd.IsGift        = false;
                scpd.OrderDateTime = DateTime.Now;
                scpd.Save();
                scp.SupplyChainPosDetails.Add(scpd);
                scp.Quantity       += 1;
                scp.UnPaidQuantity += 1;
                scp.UnPayAmount    += scpd.Amount;
                scp.PosAmount      += scpd.Amount;
                scp.Cashier         = UserStatics.ChineseName;
                scp.Save();
                bim.ConvQuantity -= 1;
                bim.InvQuantity   = bim.ConvQuantity / bim.UnitConvValue;
                bim.Save();

                FrmAddEditBindComboBoxText.BindObjectToControls(scp, panelBottom);

                TableForPosDetail = BllSupplyChainPos.GetPosDetail(PosId);
                ReloadDgvPosDetail();
                foreach (DataGridViewRow row in dgvPosDetail.Rows)
                {
                    row.Selected = true;
                }
                tbSelectItem.Text = "";
                ctUnderPay.Text   = scp.UnPayAmount.ToString();
            }
            if (e.KeyCode == Keys.Down)
            {
                bsSelectItem.MoveNext();
            }
            if (e.KeyCode == Keys.Up)
            {
                bsSelectItem.MovePrevious();
            }
        }
        override protected void DeleteCurrentRow()
        {
            BaseInfoMaterial bim = BaseInfoMaterial.FindById(DeletingRowId);

            if (bim.BaseInfoMaterialIngredients.Count == 0)
            {
                BllBaseInfoMaterial.DelCell(DeletingRowId);
            }
            else
            {
                MessageBox.Show("请先删除该商品组成耗材关系!");
            }
        }
        private void DelIngredient()
        {
            //删除记录
            if (MessageBox.Show("确认删除这(条/些)记录吗?", "询问",
                                MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    BaseInfoMaterial bim = BaseInfoMaterial.FindById(long.Parse(BaseParentId));

                    if (dgvDest.Rows.Count > 0)
                    {
                        int count = 0;

                        foreach (DataGridViewRow row in dgvDest.SelectedRows)
                        {
                            string delId = row.Cells["Id"].Value.ToString();
                            bim.ConvPrice -= (Decimal)row.Cells["单价"].Value * (Decimal)row.Cells["数量"].Value;
                            BaseInfoMaterialIngredient.DeleteAll(CK.K["Id"] == delId);
                            count++;
                        }
                        MessageBox.Show("已删除" + count + "条记录!");
                    }
                    else
                    {
                        MessageBox.Show("没有可删除的数据", "提示",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (bim.BaseInfoMaterialIngredients.Count == 0)
                    {
                        bim.IsAddToInventory = true;
                        bim.Save();
                    }
                    else
                    {
                        bim.Save();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误提示",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            bsDest.DataSource  = null;
            bsDest.DataSource  = BllBaseInfoMaterialIngredients.GetDestTable(UserStatics.OptrType, BaseParentId);
            dgvDest.DataSource = bsDest;
        }
Example #5
0
 protected override void Saving()
 {
     if (!IsAdd)
     {
         var obj = BaseInfoMaterial.FindById(long.Parse(ItemID));
         BindControlsDecimal.BindControlsToObject(obj, tabPage1);
         BindControlsDecimal.BindControlsToObject(obj, tabPage2);
         obj.Save();
     }
     else
     {
         var obj = BaseInfoMaterial.New;
         BindControlsDecimal.BindControlsToObject(obj, tabPage1);
         BindControlsDecimal.BindControlsToObject(obj, tabPage2);
         obj.OptrType = UserStatics.OptrType;
         obj.Save();
         ItemID  = obj.Id.ToString();
         IsSaved = true;
     }
 }
 private void AddIngredients()
 {
     //1.判断右边有无该编码
     if (
         BaseInfoMaterialIngredient.GetCount(CK.K["BaseInfoMaterial_Id"] == BaseParentId &&
                                             CK.K["IngredientId"] == _itemId) != 0)
     {
         MessageBox.Show("该物料已经添加");
     }
     //2.在右边加入该成品
     else
     {
         BaseInfoMaterial           bim      = BaseInfoMaterial.FindById(long.Parse(BaseParentId));
         BaseInfoMaterial           bimChild = BaseInfoMaterial.FindById(long.Parse(_itemId));
         BaseInfoMaterialIngredient baseInfoMaterialIngredient = BaseInfoMaterialIngredient.New;
         baseInfoMaterialIngredient.IngredientId = long.Parse(_itemId);
         baseInfoMaterialIngredient.MaterialName = bimChild.Name;
         baseInfoMaterialIngredient.Price        = bimChild.ConvPrice;
         if (tbAmount.Text == "")
         {
             baseInfoMaterialIngredient.Quantity = 1;
         }
         else
         {
             baseInfoMaterialIngredient.Quantity = Decimal.Parse(tbAmount.Text);
         }
         baseInfoMaterialIngredient.Cost     = baseInfoMaterialIngredient.Price * baseInfoMaterialIngredient.Quantity;
         baseInfoMaterialIngredient.OptrType = UserStatics.OptrType;
         baseInfoMaterialIngredient.Save();
         bim.BaseInfoMaterialIngredients.Add(baseInfoMaterialIngredient);
         bim.ConvPrice       += baseInfoMaterialIngredient.Price * baseInfoMaterialIngredient.Quantity;
         bim.IsAddToInventory = false;
         bim.Save();
     }
     //3.刷新右边的dgv
     bsDest.DataSource  = null;
     bsDest.DataSource  = BllBaseInfoMaterialIngredients.GetDestTable(UserStatics.OptrType, BaseParentId);
     dgvDest.DataSource = bsDest;
     //4.更新主物料的成本
 }
Example #7
0
        protected override void Loading()
        {
            ctIsAddToInventory.Checked = true;
            ctUnitConvValue.Value      = 1;

            ctCategory.DataSource    = CommonStatics.GetDict(UserStatics.OptrType, "物料分类");
            ctCategory.DisplayMember = "Name";

            ctPurchaseUnitName.DataSource    = CommonStatics.GetDict(UserStatics.OptrType, "单位");
            ctPurchaseUnitName.DisplayMember = "Name";

            ctSaleUnitName.DataSource    = CommonStatics.GetDict(UserStatics.OptrType, "单位");
            ctSaleUnitName.DisplayMember = "Name";


            if (!IsAdd || IsSaved)
            {
                var obj = BaseInfoMaterial.FindById(long.Parse(ItemID));
                BindControlsDecimal.BindObjectToControls(obj, tabPage1);
                BindControlsDecimal.BindObjectToControls(obj, tabPage2);
                bsIngredients.DataSource  = BllBaseInfoMaterialIngredients.GetDestTable(UserStatics.OptrType, ItemID);
                dgvIngredients.DataSource = bsIngredients;
            }
        }
Example #8
0
 internal static void DelCell(long id)
 {
     BaseInfoMaterial.DeleteAll(CK.K["Id"] == id);
 }