コード例 #1
0
        protected override void updateCostAndProfit(ProductCirculation cir, ProductCirculationRecord record)
        {
            /*********更新数量和成本总价**********/
            ProductStainlessDao stainlessDao = cirDao.getProductDao() as ProductStainlessDao;
            ProductStainless    stainless    = stainlessDao.FindByID(record.ProductID);

            double leftNum = stainless.Num + conf.productDirection * record.TotalNum;

            //只有采购入货才需要更新成本价,通过成本价重新计算来抵冲收付的差额
            //销售、销售退货、采购退货通过利润的计算来抵消收付的差额
            //采购退货之所以不重新计算成本价,是因为如果退货价格很高的话,可能导致成本价为负数
            if (conf.type == ProductCirculation.CirculationType.purchase)
            {
                double totalCost = stainless.PriceCost * stainless.Num + conf.productDirection * record.Price * record.TotalNum;
                if (leftNum != 0)
                {
                    double cost = totalCost / leftNum;
                    stainless.PriceCost = cost;
                }
            }

            //double乘以int会出现0.9999999的问题
            stainless.Num = (double)((decimal)stainless.Num + conf.productDirection * (decimal)record.TotalNum);

            stainlessDao.Update(stainless);


            /*************增加利润表记录**********/
            if (conf.type == ProductCirculation.CirculationType.sell || conf.type == ProductCirculation.CirculationType.sellBack || conf.type == ProductCirculation.CirculationType.purchaseBack)
            {
                SellProfit profit = new SellProfit(cir, record, stainless.PriceCost);
                SellProfitDao.getInstance().Insert(profit);
            }
        }
コード例 #2
0
        /// <summary>
        /// event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton_save_Click(object sender, EventArgs e)
        {
            ProductStainless product = null;

            if (this.getProduct(out product) == false)
            {
                return;
            }

            if (openMode == 0)
            {
                ProductStainlessDao.getInstance().Insert(product);
                MessageBox.Show("保存货品成功,在相应的类别目录下可以找到该货品!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (openMode == 1)
            {
                product.ID = productID;
                bool basicResult = ProductStainlessDao.getInstance().Update(product);
                if (basicResult)
                {
                    MessageBox.Show("修改货品成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            this.invokeUpdateNotify(UpdateType.ProductUpdate);
            this.Close();
        }
コード例 #3
0
        private bool getProduct(out ProductStainless product)
        {
            double price_purchase, price_sell, price_cost, num, quantityPerPiece;
            string name;
            int    categoryID;

            if (ValidateUtility.getName(this.textBox_name, this.errorProvider1, out name) &&
                ValidateUtility.getDouble(this.textBox_purchasePrice, this.errorProvider1, true, true, out price_purchase) &&
                ValidateUtility.getDouble(this.textBox_sellPrice, this.errorProvider1, true, true, out price_sell) &&
                ValidateUtility.getDouble(this.textBox_cost, this.errorProvider1, false, false, out price_cost) &&
                ValidateUtility.getDouble(this.textBox_quantityPerPiece, this.errorProvider1, false, true, out quantityPerPiece) &&
                ValidateUtility.getDouble(this.textBox_libNum, this.errorProvider1, false, false, out num) &&
                this.getCategoryID(out categoryID))
            {
                product    = new ProductStainless(this.textBox_serial.Text, name, categoryID, price_purchase, price_sell, this.comboBox_unit.Text, quantityPerPiece, this.textBox_comment.Text, this.radioButton2.Checked);
                product.ID = productID;
                //2018-4-16修正bug
                product.PriceCost = price_cost;
                product.Num       = num;
                return(true);
            }
            else
            {
                product = null;
                return(false);
            }
        }
コード例 #4
0
        //弃核
        protected override void cancelUpdateCostAndProfit(ProductCirculation cir, ProductCirculationRecord record)
        {
            /*********更新数量**********/
            ProductStainlessDao stainlessDao = cirDao.getProductDao() as ProductStainlessDao;
            ProductStainless    stainless    = stainlessDao.FindByID(record.ProductID);

            stainless.Num = (double)((decimal)stainless.Num - conf.productDirection * (decimal)record.TotalNum);
            stainlessDao.Update(stainless);
        }
コード例 #5
0
        protected override void productEditingControl_valueSetted(object sender, LookupArg arg)
        {
            //File.AppendAllText("e:\\debug.txt", string.Format("value changed, thread:{0}\r\n", System.Threading.Thread.CurrentThread.ManagedThreadId));

            DataGridViewLookupEditingControl control = (sender as DataGridViewLookupEditingControl);

            //File.AppendAllText("e:\\debug.txt", string.Format("value changed, control hash code={0}, control name={1}\r\n", control.GetHashCode(), control.Name));
            try
            {
                //File.AppendAllText("e:\\debug.txt", string.Format("value changed, dataGridView hash code={0}, dataGridView name={1}\r\n", control.EditingControlDataGridView.GetHashCode(), control.EditingControlDataGridView.Name));
                if (control.EditingControlDataGridView.Rows.Count == 0 || control.EditingControlDataGridView.CurrentCell == null)
                {
                    throw new Exception();
                }

                //if(control.EditingControlDataGridView.CurrentCell.OwningColumn.Name == "product")
                //这里为什么要判断呢?
                if (!string.IsNullOrEmpty(arg.ArgName) && arg.ArgName == "ProductStainless")
                {
                    int productID = (int)(arg.Value);
                    int oldID     = -1;
                    int.TryParse((control.EditingControlDataGridView.Rows[control.EditingControlRowIndex].Cells["product"].Value).ToString(), out oldID);
                    if (productID != oldID)
                    {
                        ProductStainless product = ProductStainlessDao.getInstance().FindByID(productID);
                        //stone 临时关闭
                        control.EditingControlDataGridView.Rows[control.EditingControlRowIndex].Cells["serial"].Value           = product.Serial;
                        control.EditingControlDataGridView.Rows[control.EditingControlRowIndex].Cells["quantityPerPiece"].Value = product.QuantityPerPiece;
                        control.EditingControlDataGridView.Rows[control.EditingControlRowIndex].Cells["unit"].Value             = product.Unit;
                        if (conf.type == ProductCirculation.CirculationType.sell || conf.type == ProductCirculation.CirculationType.sellBack)
                        {
                            //这里要加个.ToString(),可能自定义Cell的value类型不大一样
                            control.EditingControlDataGridView.Rows[control.EditingControlRowIndex].Cells["price"].Value = product.PriceSell.ToString();
                        }
                        else
                        {
                            control.EditingControlDataGridView.Rows[control.EditingControlRowIndex].Cells["price"].Value = product.PricePurchase.ToString();
                        }
                    }
                }
                //not reasonal
                setSubTotalPrice(control.EditingControlRowIndex);
                setTotalPrice();
            }
            catch (Exception ex)
            {
                //File.AppendAllText("e:\\debug.txt",string.Format("exception, dataGridView.Rows.Count={0}\r\n", this.dataGridView1.Rows.Count));
                //File.AppendAllText("e:\\debug.txt", string.Format("exception, dataGridView hash code={0}, dataGridView name={1}\r\n", control.EditingControlDataGridView.GetHashCode(), control.EditingControlDataGridView.Name));
                System.Threading.Thread.Sleep(0);
            }

            this.resetNeedSave(true);
            this.recordChanged = true;
        }
コード例 #6
0
        public bool Update(ProductStainless info)
        {
            try
            {
                string commandText = string.Format("update ProductStainless set serial='{0}', name='{1}', comment='{2}', parent={3}, pricePurchase={4}, priceCost = {5}, priceSell={6}, unit='{7}', quantityPerPiece={8}, num={9}, disable={10} where ID={11}",
                                                   info.Serial, info.Name, info.Comment, info.CategoryID, info.PricePurchase, info.PriceCost, info.PriceSell, info.Unit, info.QuantityPerPiece, info.Num, info.Disable, info.ID);

                DbHelperAccess.executeNonQuery(commandText);
                return(true);
            }
            catch (Exception ex) {
                return(false);
            }
        }
コード例 #7
0
 public int Insert(ProductStainless info)
 {
     try
     {
         string commandText = string.Format(
             "insert into ProductStainless(serial, name, comment, parent, pricePurchase, priceCost, priceSell, unit, quantityPerPiece, disable) values('{0}', '{1}', '{2}', {3}, {4}, {5}, {6}, '{7}', {8}, {9})",
             info.Serial, info.Name, info.Comment, info.CategoryID, info.PricePurchase, info.PriceCost, info.PriceSell, info.Unit, info.QuantityPerPiece, info.Disable);
         DbHelperAccess.executeNonQuery(commandText);
         int productID = DbHelperAccess.executeMax("ID", "ProductStainless");
         return(productID);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #8
0
        public ProductStainless FindByID(int ID)
        {
            string           commandText = string.Format("select * from ProductStainless where ID={0}", ID);
            DataRow          dr          = DbHelperAccess.executeQueryGetOneRow(commandText);
            ProductStainless product     = new ProductStainless();

            if (dr != null)
            {
                product.ID         = (int)dr["ID"];
                product.Name       = dr["name"] as string;
                product.Serial     = dr["serial"] as string;
                product.CategoryID = (int)dr["parent"];

                double quantityPerPiece;
                double.TryParse(dr["quantityPerPiece"].ToString(), out quantityPerPiece);
                product.QuantityPerPiece = quantityPerPiece;
                product.Unit             = dr["unit"] as string;

                double num;
                double.TryParse(dr["num"].ToString(), out num);
                product.Num = num;

                product.Comment = dr["comment"] as string;

                double pricePurchase, priceSell, priceCost;
                double.TryParse(dr["pricePurchase"].ToString(), out pricePurchase);
                product.PricePurchase = pricePurchase;

                double.TryParse(dr["priceSell"].ToString(), out priceSell);
                product.PriceSell = priceSell;

                double.TryParse(dr["priceCost"].ToString(), out priceCost);
                product.PriceCost = priceCost;

                bool disable;
                bool.TryParse(dr["disable"].ToString(), out disable);
                product.Disable = disable;

                return(product);
            }
            return(null);
        }
コード例 #9
0
        private void initProduct()
        {
            this.label4.Text = "编辑货品, ID:" + productID;

            ProductStainless product = ProductStainlessDao.getInstance().FindByID(productID);

            this.textBox_name.Text   = product.Name;
            this.textBox_serial.Text = product.Serial;

            this.comboBoxTree_category.setSelectNode(product.CategoryID.ToString());

            this.textBox_purchasePrice.Text = product.PricePurchase.ToString();
            this.textBox_sellPrice.Text     = product.PriceSell.ToString();
            this.textBox_cost.Text          = product.PriceCost.ToString();

            this.textBox_quantityPerPiece.Text = product.QuantityPerPiece.ToString();
            this.comboBox_unit.Text            = product.Unit;

            this.textBox_libNum.Text = product.Num.ToString();

            this.textBox_comment.Text = product.Comment;
            this.radioButton2.Checked = product.Disable;
        }