Beispiel #1
0
        // Add a new item to database.
        //  Either by create new or duplicate existing.
        private void AddItem()
        {
            InventoryItemType item = GetItemInfoFromUI(true /*insert*/);

            if (item == null)
            {
                return;
            }

            int newItemId = ItemDAL.InsertOneItem(item);

            if (newItemId <= 0)
            {
                MessageBox.Show("不能添加新商品,可能商品的SKU和已有商品重复了!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Add this item to tree view.
            TreeNode[] nodes = this.treeViewCategories.Nodes.Find(item.CategoryId.ToString(), true);
            if (nodes.Length == 1)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = string.Format("[{0}] {1}", item.ItemSKU, item.ItemName);
                ItemCompactInfo itemInfo = new ItemCompactInfo(newItemId, item.CategoryId, item.ItemName, item.ItemSKU);
                newNode.Tag = itemInfo;
                nodes[0].Nodes.Add(newNode);
            }

            MessageBox.Show("恭喜,添加新商品成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #2
0
        private void dgvItems_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != SKUColIndex)
            {
                return;
            }

            DataGridViewCell cell = this.dgvItems.CurrentCell;

            if (cell == null)
            {
                return;
            }

            DataGridViewRow row = cell.OwningRow;

            if (row == null)
            {
                return;
            }

            FrmSelectItemSKU frm = new FrmSelectItemSKU();

            frm.StartPosition = FormStartPosition.CenterParent;
            frm.ShowDialog();

            if (frm.SKU != null)
            {
                cell.Value = frm.SKU;
                InventoryItemType item = ItemDAL.GetItemBySKU(frm.SKU);
                row.Cells[ItemTitleColIndex].Value = item.ItemName;
            }
        }
Beispiel #3
0
        private void CreateNewItemStockInNote()
        {
            if (mEditMode != EditMode.CreateNew)
            {
                return;
            }

            String itemSku = this.textBoxItemSKU.Text;

            if (itemSku == "")
            {
                MessageBox.Show("商品sku错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            InventoryItemType item = ItemDAL.GetItemBySKU(itemSku);

            if (item == null)
            {
                MessageBox.Show("无此sku商品!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            String sourcingNoteIdStr = this.textBoxSourcingNoteId.Text;

            String stockInNumStr = this.textBoxStockInNum.Text;
            int    stockInNum    = 0;

            if (stockInNumStr == "" || !Int32.TryParse(stockInNumStr, out stockInNum))
            {
                MessageBox.Show("商品入库数量错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DateTime stockInDate = this.dateTimePickerStockInTime.Value;

            ItemStockInNoteType note = new ItemStockInNoteType();

            note.ItemSKU        = itemSku;
            note.ItemTitle      = item.ItemName;
            note.SourcingNoteId = sourcingNoteIdStr;
            note.StockInNum     = stockInNum;
            note.StockInDate    = stockInDate;
            note.Comment        = textBoxComment.Text;

            int noteId = ItemStockInNoteDAL.InsertOneItemStockInNote(note);

            if (noteId <= 0)
            {
                MessageBox.Show("创建入库单失败!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Increase the item stock number.
            ItemDAL.IncreaseItem(itemSku, stockInNum);

            MessageBox.Show(String.Format("创建入库单成功,入库单号{0}!", noteId),
                            "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #4
0
        private void LoadExistingSourcingNote()
        {
            if (mSourcingNote == null)
            {
                return;
            }

            SupplierType supplier = SupplierDAL.GetSupplierById(mSourcingNote.SupplierId);

            if (supplier == null)
            {
                return;
            }

            mSupplier = supplier;

            this.textBoxSupplier.Text     = supplier.SupplierName;
            this.textBoxExtraFee.Text     = mSourcingNote.ExtraFee.ToString();
            this.textBoxShippingFee.Text  = mSourcingNote.ShippingFee.ToString();
            this.textBoxTotalFee.Text     = mSourcingNote.TotalFee.ToString();
            this.textBoxComment.Text      = mSourcingNote.Comment;
            this.dateTimePickerDate.Value = mSourcingNote.SourcingDate;

            String skuListStr   = mSourcingNote.ItemSkuList;
            String numListStr   = mSourcingNote.ItemNumList;
            String priceListStr = mSourcingNote.ItemPriceList;

            String [] skuArr   = skuListStr.Split(new char[] { ',' });
            String [] numArr   = numListStr.Split(new char[] { ',' });
            String[]  priceArr = priceListStr.Split(new char[] { ',' });

            if (skuArr.Length != numArr.Length || skuArr.Length != priceArr.Length)
            {
                return;
            }

            for (int ii = 0; ii < skuArr.Length; ++ii)
            {
                String            sku  = skuArr[ii];
                InventoryItemType item = ItemDAL.GetItemBySKU(sku);
                if (item == null)
                {
                    continue;
                }

                DataRow dr = mItemsTable.NewRow();
                dr["ItemSKU"]   = sku;
                dr["ItemName"]  = item.ItemName;
                dr["ItemPrice"] = StringUtil.GetSafeDouble(priceArr[ii]);
                dr["ItemCount"] = StringUtil.GetSafeInt(numArr[ii]);

                mItemsTable.Rows.Add(dr);
            }

            this.dgvItems.DataSource = mItemsTable;
        }
Beispiel #5
0
        public static bool IncreaseItem(string sku, int count)
        {
            InventoryItemType item = GetItemBySKU(sku);

            if (item == null)
            {
                return(false);
            }

            int newStock = item.ItemStockNum + count;

            String sql = string.Format("update [Item] set ItemStockNum={0} where ItemSKU='{1}'", newStock, sku);

            DataFactory.ExecuteSql(sql);
            return(true);
        }
Beispiel #6
0
        private void treeViewCategories_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode oldNode;

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                Point    pt         = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                TreeNode targetNode = ((TreeView)sender).GetNodeAt(pt);

                object tag = targetNode.Tag;
                if (tag == null || tag.GetType() != typeof(ItemCategoryType))
                {
                    return;
                }
                ItemCategoryType catInfo = (ItemCategoryType)tag;

                oldNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                if (oldNode.Tag == null || oldNode.Tag.GetType() != typeof(ItemCompactInfo))
                {
                    return;
                }

                ItemCompactInfo itemInfo = (ItemCompactInfo)oldNode.Tag;
                if (itemInfo == null)
                {
                    return;
                }

                InventoryItemType item = ItemDAL.GetItemById(itemInfo.ItemId);
                if (item == null)
                {
                    return;
                }

                if (item.CategoryId == catInfo.CategoryId)
                {
                    return;
                }

                ItemDAL.ModifyItemCategory(item.ItemId, catInfo.CategoryId);

                targetNode.Nodes.Add((TreeNode)oldNode.Clone());
                targetNode.Expand();
                //Remove Original Node
                oldNode.Remove();
            }
        }
Beispiel #7
0
        private void ToolStripMenuItemDelItemStockInNote_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确认删除入库单么?\r\n删除后,相应商品的库存将被扣除。",
                                "确认删除?",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            int    rowIdx = this.pagedDgvItem.DgvData.CurrentRow.Index;
            String noteId = this.pagedDgvItem.DgvData.Rows[rowIdx].Cells[0].Value.ToString();

            ItemStockInNoteType note = ItemStockInNoteDAL.GetOneItemStockInNote(noteId);

            if (note == null)
            {
                return;
            }

            // Decrease the stock.
            //  First check validity.
            String itemSKU = note.ItemSKU;

            InventoryItemType item = ItemDAL.GetItemBySKU(itemSKU);

            if (item == null)
            {
                return;
            }

            if (item.ItemStockNum < note.StockInNum)
            {
                MessageBox.Show(String.Format("商品{0}的原库存为{1},删除入库单后其库存为{2},非法操作",
                                              itemSKU, item.ItemStockNum, item.ItemStockNum - note.StockInNum),
                                "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ItemDAL.DecreaseItem(itemSKU, note.StockInNum);

            ItemStockInNoteDAL.DeleteOneItemStockInNote(noteId);
            MessageBox.Show(String.Format("入库单{0}已删除", noteId), "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);

            pagedDgvItem.LoadData();
        }
Beispiel #8
0
        public static bool DeleteOneItem(int itemId)
        {
            bool result = false;

            InventoryItemType itemInfo = GetItemById(itemId);

            if (itemInfo == null || itemInfo.ItemId <= 0)
            {
                return(false);
            }

            String sql = string.Format("delete from [Item] where ItemId={0}", itemId);

            DataFactory.ExecuteSql(sql);
            result = true;

            return(result);
        }   // DeleteOneItem
Beispiel #9
0
        public static bool ModifyItemNote(InventoryItemType item)
        {
            bool result = false;

            // Delete and insert one
            if (item == null || item.ItemId < 0)
            {
                return(false);
            }

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Update [Item] set ItemNote=@ItemNote where ItemId=@ItemId";

            DataFactory.AddCommandParam(cmd, "@ItemNote", DbType.String, StringUtil.GetSafeString(item.ItemNote));
            DataFactory.AddCommandParam(cmd, "@ItemId", DbType.Int32, item.ItemId);

            try
            {
                if (DataFactory.DbConnection.State == ConnectionState.Closed)
                {
                    DataFactory.DbConnection.Open();
                }
                cmd.ExecuteNonQuery();
                result = true;
            }
            catch (DataException)
            {
                // Write to log here.
                result = false;
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                {
                    DataFactory.DbConnection.Close();
                }
            }

            return(result);
        }
Beispiel #10
0
        public static bool ShipItem(string sku, int count)
        {
            InventoryItemType item = GetItemBySKU(sku);

            if (item == null)
            {
                return(false);
            }

            if (item.IsGroupItem)
            {
                List <string> skus = item.SubItemSKUList;
                foreach (string subItemSku in skus)
                {
                    DecreaseItem(subItemSku, count);
                }
            }
            else
            {
                DecreaseItem(sku, count);
            }

            return(true);
        }
        private void ToolStripMenuItemDelDeliveryNote_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确认刪除该进货单么?\r\n。",
                                "确认删除?",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            int    rowIdx         = this.pagedDgvDeliveryNote.DgvData.CurrentRow.Index;
            String deliveryNoteId = this.pagedDgvDeliveryNote.DgvData.Rows[rowIdx].Cells[0].Value.ToString();

            DeliveryNoteType note = DeliveryNoteDAL.GetOneDeliveryNote(deliveryNoteId);

            if (note == null)
            {
                return;
            }

            // Restore the stock.
            String tranIdStr = note.DeliveryOrderIds;

            String[] tranIds      = tranIdStr.Split(new char[] { ',', ' ' });
            String   promptString = "";

            foreach (String tranId in tranIds)
            {
                EbayTransactionType trans = EbayTransactionDAL.GetOneTransactonById(tranId);
                if (trans == null || trans.ItemSKU == null || trans.ItemSKU == "")
                {
                    MessageBox.Show(String.Format("订单号{0}异常", tranId), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }

                String            itemSku      = trans.ItemSKU;
                int               saleQuantity = trans.SaleQuantity;
                InventoryItemType item         = ItemDAL.GetItemBySKU(itemSku);
                if (item == null)
                {
                    MessageBox.Show(String.Format("无此sku商品{0}", itemSku), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }

                ItemDAL.IncreaseItem(itemSku, saleQuantity);
                promptString += String.Format("\nsku:{0} 原库存 {1} => 现库存 {2}", itemSku, item.ItemStockNum, item.ItemStockNum + saleQuantity);

                //
                // Update transaction delivery status.
                //
                EbayTransactionDAL.UpdateTransactionDeliveryStatus(tranId, false, -1);
            }

            DeliveryNoteDAL.DeleteOneDeliveryNote(deliveryNoteId);

            pagedDgvDeliveryNote.LoadData();

            // Indicate main form to update view.
            Deleted = true;

            MessageBox.Show(String.Format("删除发货单成功 {0}", promptString),
                            "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #12
0
        public static bool ModifyOneItem(InventoryItemType item)
        {
            bool result = false;

            // Delete and insert one
            if (item == null || item.ItemId < 0)
            {
                return(false);
            }

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Update [Item] set CategoryId=@CategoryId, ItemName=@ItemName, ItemSKU=@ItemSKU, ItemImagePath=@ItemImagePath,"
                              + " ItemStockShresholdNum=@ItemStockShresholdNum, ItemStockNum=@ItemStockNum, ItemSourcingInfo=@ItemSourcingInfo, ItemCost=@ItemCost, ItemWeight=@ItemWeight, "
                              + " ItemCustomName=@ItemCustomName, ItemCustomWeight=@ItemCustomWeight, ItemCustomCost=@ItemCustomCost, ItemAddDateTime=@ItemAddDateTime, "
                              + " IsGroupItem=@IsGroupItem, SubItemSKUs=@SubItemSKUs, ItemSourcingURL=@ItemSourcingURL, ItemDispatchTips=@ItemDispatchTips, ItemNote=@ItemNote where ItemId=@ItemId";

            DataFactory.AddCommandParam(cmd, "@CategoryId", DbType.Int32, item.CategoryId);
            DataFactory.AddCommandParam(cmd, "@ItemName", DbType.String, GetDefaultValue(item.ItemName));

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, StringUtil.GetSafeString(item.ItemSKU));
            DataFactory.AddCommandParam(cmd, "@ItemImagePath", DbType.String, item.ItemImagePath);

            DataFactory.AddCommandParam(cmd, "@ItemStockShresholdNum", DbType.Int32, item.ItemStockShresholdNum);
            DataFactory.AddCommandParam(cmd, "@ItemStockNum", DbType.Int32, item.ItemStockNum);

            DataFactory.AddCommandParam(cmd, "@ItemSourcingInfo", DbType.String, GetDefaultValue(item.ItemSourcingInfo));
            DataFactory.AddCommandParam(cmd, "@ItemCost", DbType.Double, item.ItemCost);

            DataFactory.AddCommandParam(cmd, "@ItemWeight", DbType.Double, item.ItemWeight);
            DataFactory.AddCommandParam(cmd, "@ItemCustomName", DbType.String, GetDefaultValue(item.ItemCustomName));

            DataFactory.AddCommandParam(cmd, "@ItemCustomWeight", DbType.Double, item.ItemCustomWeight);
            DataFactory.AddCommandParam(cmd, "@ItemCustomCost", DbType.Double, item.ItemCustomCost);

            DataFactory.AddCommandParam(cmd, "@ItemAddDateTime", DbType.DateTime, item.ItemAddDateTime.ToString());

            DataFactory.AddCommandParam(cmd, "@IsGroupItem", DbType.Boolean, item.IsGroupItem);
            DataFactory.AddCommandParam(cmd, "@SubItemSKUs", DbType.String, GetDefaultValue(item.SubItemSKUs));

            DataFactory.AddCommandParam(cmd, "@ItemSourcingURL", DbType.String, StringUtil.GetSafeString(item.ItemSourcingURL));
            DataFactory.AddCommandParam(cmd, "@ItemDispatchTips", DbType.String, "");
            DataFactory.AddCommandParam(cmd, "@ItemNote", DbType.String, StringUtil.GetSafeString(item.ItemNote));

            DataFactory.AddCommandParam(cmd, "@ItemId", DbType.Int32, item.ItemId);

            try
            {
                if (DataFactory.DbConnection.State == ConnectionState.Closed)
                {
                    DataFactory.DbConnection.Open();
                }
                cmd.ExecuteNonQuery();
                result = true;
            }
            catch (DataException)
            {
                // Write to log here.
                result = false;
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                {
                    DataFactory.DbConnection.Close();
                }
            }

            return(result);
        }   // ModifyOneItem
Beispiel #13
0
        private InventoryItemType GetItemInfoFromUI(bool isInsert)
        {
            InventoryItemType item = new InventoryItemType();

            TreeNode node = this.treeViewCategories.SelectedNode;

            if (node == null)
            {
                MessageBox.Show("请选择商品类别");
                return(null);
            }

            if (isInsert)
            {
                if (node.Tag.GetType() != typeof(ItemCategoryType))
                {
                    MessageBox.Show("请选择商品类别");
                    return(null);
                }

                ItemCategoryType category = (ItemCategoryType)node.Tag;
                if (category == null)
                {
                    MessageBox.Show("请选择商品类别");
                    return(null);
                }

                item.CategoryId = category.CategoryId;
                if (item.CategoryId <= 0)
                {
                    MessageBox.Show("请选择商品类别");
                    return(null);
                }
            }
            else
            {
                // modify
                if (node.Tag.GetType() != typeof(ItemCompactInfo))
                {
                    MessageBox.Show("请选择商品");
                    return(null);
                }
            }

            item.ItemName = this.textBoxItemName.Text;
            if (item.ItemName == "")
            {
                MessageBox.Show("请输入商品名");
                return(null);
            }

            item.ItemSKU = this.textBoxItemSKU.Text;
            if (item.ItemSKU == "")
            {
                MessageBox.Show("请输入商品SKU");
                return(null);
            }

            if (this.textBoxItemImagePath.Text.Trim() == "")
            {
                if (isInsert)
                {
                    MessageBox.Show("请选择商品图片");
                    return(null);
                }
            }
            else
            {
                string imagePath = this.textBoxItemImagePath.Text.Trim();
                if (File.Exists(imagePath) == false)
                {
                    MessageBox.Show("商品图片路径错误.");
                    return(null);
                }

                //FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
                //byte[] buffer = new byte[fs.Length];
                //fs.Read(buffer, 0, buffer.Length);
                //fs.Close();
                //item.ItemImage = buffer;
                item.ItemImagePath = imagePath;
            }

            if (this.textBoxItemStockShreshold.Text == "")
            {
                MessageBox.Show("商品库存警戒值错误");
                return(null);
            }

            item.ItemStockShresholdNum = Int32.Parse(this.textBoxItemStockShreshold.Text.Trim());

            string itemStockStr = this.textBoxItemStock.Text;

            if (itemStockStr.Trim() == "")
            {
                MessageBox.Show("商品库存值错误");
                return(null);
            }

            item.ItemStockNum = StringUtil.GetSafeInt(itemStockStr);

            //item.ItemSourcingInfo = this.textBoxItemSourcingInfo.Text;

            //item.ItemSourcingURL = this.textBoxSourcingURL.Text;

            //string itemCostStr = this.textBoxItemCost.Text.Trim();
            //if (itemCostStr == "")
            //{
            //    MessageBox.Show("商品成本值错误");
            //    return null;
            //}
            //item.ItemCost = StringUtil.GetSafeDouble(itemCostStr);

            string itemWeightStr = this.textBoxItemWeight.Text.Trim();

            if (itemWeightStr == "")
            {
                MessageBox.Show("商品重量值错误");
                return(null);
            }
            item.ItemWeight = StringUtil.GetSafeDouble(itemWeightStr);

            item.ItemCustomName = this.textBoxCustomName.Text.Trim();

            string itemCustomWeightStr = this.textBoxItemCustomWeight.Text.Trim();

            if (itemCustomWeightStr == "")
            {
                item.ItemCustomWeight = 0.0;
            }
            else
            {
                item.ItemCustomWeight = StringUtil.GetSafeDouble(itemCustomWeightStr);
            }

            string itemCustomCostStr = this.textBoxItemCustomValue.Text.Trim();

            if (itemCustomCostStr == "")
            {
                item.ItemCustomCost = 0.0;
            }
            else
            {
                item.ItemCustomCost = StringUtil.GetSafeDouble(itemCustomCostStr);
            }

            item.ItemAddDateTime = DateTime.Now;

            // IsGroupItem
            item.IsGroupItem = false;
            item.SubItemSKUs = "";

            return(item);
        }
Beispiel #14
0
        private SourcingNoteType GetSourcingNoteFromUI(out double totalFee)
        {
            totalFee = 0.0;

            SourcingNoteType note = new SourcingNoteType();

            if (mSupplier == null)
            {
                MessageBox.Show("未选中任何供应商", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            DateTime date = dateTimePickerDate.Value;

            String skuList   = "";
            String priceList = "";
            String countList = "";

            bool first = true;

            foreach (DataGridViewRow row in this.dgvItems.Rows)
            {
                String sku   = StringUtil.GetSafeString(row.Cells[SKUColIndex].Value);
                Double price = StringUtil.GetSafeDouble(row.Cells[ItemPriceColIndex].Value);
                int    count = StringUtil.GetSafeInt(row.Cells[ItemCountColIndex].Value);

                InventoryItemType item = ItemDAL.GetItemBySKU(sku);
                if (item == null)
                {
                    continue;
                }

                if (count == 0)
                {
                    continue;
                }

                totalFee += count * price;

                if (first)
                {
                    skuList   = sku;
                    priceList = price.ToString();
                    countList = count.ToString();
                    first     = false;
                }
                else
                {
                    skuList   += "," + sku;
                    priceList += "," + price.ToString();
                    countList += "," + count.ToString();
                }
            }

            double extraFee = 0.0;

            if (!Double.TryParse(this.textBoxExtraFee.Text, out extraFee))
            {
                MessageBox.Show("其他费用必须是小数", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }


            double shippingFee = 0.0;

            if (!Double.TryParse(this.textBoxShippingFee.Text, out shippingFee))
            {
                MessageBox.Show("运费必须是小数", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            totalFee += extraFee;
            totalFee += shippingFee;

            note.SupplierId    = mSupplier.SupplierID;
            note.SourcingDate  = date;
            note.ItemSkuList   = skuList;
            note.ItemNumList   = countList;
            note.ItemPriceList = priceList;
            note.ExtraFee      = extraFee;
            note.ShippingFee   = shippingFee;
            note.TotalFee      = totalFee;
            note.Comment       = this.textBoxComment.Text;

            if (mEditMode == EditMode.EditExisting)
            {
                note.SourcingId = mSourcingNote.SourcingId;
            }

            return(note);
        }
        private void CreateDeliveryNote()
        {
            if (mEditMode != EditMode.CreatNew && mEditMode != EditMode.CreateFromTrans)
            {
                // We are not creating a new delivery note.
                return;
            }

            // Sanity check.
            if (mDtTransactions == null || mDtTransactions.Rows.Count == 0)
            {
                return;
            }

            //
            // Add a new delivery note.
            //

            // tranIds will be like "2264,2265,2266"
            String tranIds  = "";
            bool   firstRow = true;

            foreach (DataRow dr in mDtTransactions.Rows)
            {
                String tranIdLoc = StringUtil.GetSafeString(dr["TransactionId"]);
                if (tranIdLoc == null || tranIdLoc == "")
                {
                    continue;
                }

                if (!firstRow)
                {
                    tranIds += ",";
                }
                else
                {
                    firstRow = false;
                }

                tranIds += tranIdLoc;
            }

            double fee      = 0.0;
            double extraFee = 0.0;

            Double.TryParse(textBoxFee.Text, out fee);
            Double.TryParse(textBoxExtraFee.Text, out extraFee);

            DeliveryNoteType deliveryNote = new DeliveryNoteType();

            deliveryNote.DeliveryDate     = DateTime.Now;
            deliveryNote.DeliveryOrderIds = tranIds;
            deliveryNote.DeliveryUser     = "";
            deliveryNote.DeliveryFee      = fee;
            deliveryNote.DeliveryExtraFee = extraFee;
            deliveryNote.DeliveryComment  = textBoxComment.Text;

            // Decrease the stock.
            // Two runs:
            //  first run check validity.
            //  second run do the actual stock decreament.
            // This is to ensure the data integrity.
            Dictionary <String, int> itemSkuToTotalDecreased = new Dictionary <string, int>();

            String stockChangePrompt = "";

            for (int ii = 0; ii < 2; ++ii)
            {
                foreach (DataRow dr in mDtTransactions.Rows)
                {
                    String tranId       = StringUtil.GetSafeString(dr["TransactionId"]);
                    String itemSku      = StringUtil.GetSafeString(dr["ItemSKU"]);
                    int    saleQuantity = StringUtil.GetSafeInt(dr["SaleQuantity"]);

                    if (0 == ii)
                    {
                        if (itemSku == "")
                        {
                            MessageBox.Show(String.Format("订单{0}没有关联商品", tranId),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        InventoryItemType item = ItemDAL.GetItemBySKU(itemSku);
                        if (item == null)
                        {
                            MessageBox.Show(String.Format("商品不存在, sku={0}", itemSku),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        if (!itemSkuToTotalDecreased.ContainsKey(itemSku))
                        {
                            itemSkuToTotalDecreased.Add(itemSku, saleQuantity);
                        }
                        else
                        {
                            itemSkuToTotalDecreased[itemSku] += saleQuantity;
                        }

                        if (item.ItemStockNum < itemSkuToTotalDecreased[itemSku])
                        {
                            MessageBox.Show(String.Format("商品{0}库存不足,实际库存{1} < 售出数{2}",
                                                          itemSku, item.ItemStockNum, itemSkuToTotalDecreased[itemSku]),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    if (1 == ii)
                    {
                        InventoryItemType item = ItemDAL.GetItemBySKU(itemSku);
                        int origStock          = item.ItemStockNum;

                        if (!ItemDAL.DecreaseItem(itemSku, saleQuantity))
                        {
                            MessageBox.Show(String.Format("更新库存失败:商品{0}库存不足销售数量{1}", itemSku, saleQuantity),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        stockChangePrompt += String.Format("\nsku: {0}, 原库存 {1} => 现库存 {2}",
                                                           itemSku, origStock, origStock - saleQuantity);
                    }
                }
            } // End of two runs

            //
            // Create a new delivery note.
            //
            int deliveryNoteId = -1;

            if ((deliveryNoteId = DeliveryNoteDAL.InsertOneDeliveryNote(deliveryNote)) <= 0)
            {
                MessageBox.Show("创建发货单失败", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //
            // Update transaction delivery status.
            //
            foreach (DataRow dr in mDtTransactions.Rows)
            {
                String tranId = StringUtil.GetSafeString(dr["TransactionId"]);
                EbayTransactionDAL.UpdateTransactionDeliveryStatus(tranId, true, deliveryNoteId);
            }

            // Indicate main form to update data.
            Added = true;

            MessageBox.Show(String.Format("创建发货单成功 {0}", stockChangePrompt),
                            "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #16
0
        // Modify an existing item.
        //
        private void ModifyItem()
        {
            // Should be refactored.
            TreeNode node = treeViewCategories.SelectedNode;

            if (node == null || node.Tag == null)
            {
                return;
            }

            if (node.Tag.GetType() != typeof(ItemCompactInfo))
            {
                return;
            }

            ItemCompactInfo itemInfo = (ItemCompactInfo)(node.Tag);

            if (itemInfo == null)
            {
                return;
            }

            InventoryItemType item = ItemDAL.GetItemById(itemInfo.ItemId);

            if (item == null)
            {
                return;
            }

            InventoryItemType newItemInfo = GetItemInfoFromUI(false);

            if (newItemInfo == null)
            {
                return;
            }

            // CAUIION: we don't allow user to change the stock number directly.
            // ZHI_TODO:
            //newItemInfo.ItemStockNum = item.ItemStockNum;

            newItemInfo.ItemId     = item.ItemId;
            newItemInfo.CategoryId = item.CategoryId;
            if (newItemInfo.ItemImagePath == null)
            {
                newItemInfo.ItemImagePath = item.ItemImagePath;
            }
            newItemInfo.ItemNote = item.ItemNote;

            if (MessageBox.Show(string.Format("确认修改商品 {0}", itemInfo.ItemName), "请确认",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                == System.Windows.Forms.DialogResult.Yes)
            {
                bool result = ItemDAL.ModifyOneItem(newItemInfo);
                if (result)
                {
                    MessageBox.Show("修改商品成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    itemInfo.ItemName = newItemInfo.ItemName;
                    itemInfo.ItemSKU  = newItemInfo.ItemSKU;
                    node.Tag          = itemInfo;
                    if (newItemInfo.ItemName != item.ItemName)
                    {
                        node.Text = string.Format("[{0}] {1}", newItemInfo.ItemSKU, newItemInfo.ItemName);
                    }
                }
                else
                {
                    MessageBox.Show("修改商品失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #17
0
        public static bool ExportTransactionsTo4pxExcel(List <EbayTransactionType> transList, string filePath)
        {
            FileInfo fileInfo = new FileInfo(EbayConstants.ExcelTemplateFor4pxFilePath);

            if (!fileInfo.Exists)
            {
                Logger.WriteSystemLog(string.Format("{0} doesn't exist!", EbayConstants.ExcelTemplateFor4pxFilePath));
                return(false);
            }

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            if (excelApp == null)
            {
                Logger.WriteSystemLog("Cannot create Excel Application object.");
                return(false);
            }

            Microsoft.Office.Interop.Excel.Workbooks workbooks = excelApp.Workbooks;
            String excelTemplateFilePath = string.Format("{0}\\{1}", Environment.CurrentDirectory, EbayConstants.ExcelTemplateFor4pxFilePath);

            Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(excelTemplateFilePath, Type.Missing,
                                                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                                       Type.Missing, Type.Missing, Type.Missing);

            if (workbook == null)
            {
                Logger.WriteSystemLog("不能打开excel模板文件.");
                return(false);
            }

            Microsoft.Office.Interop.Excel.Worksheet worksheet = workbook.Sheets[1]; //First worksheet

            int curRow = 2;

            foreach (EbayTransactionType trans in transList)
            {
                if (trans.IsPaid == false)
                {
                    Logger.WriteSystemLog("Try to export unpaid transaction!");
                    return(false);
                }
                if (trans.ItemSKU == "")
                {
                    Logger.WriteSystemLog("Try to export transaction with item that has no SKU!");
                    return(false);
                }
                if (trans.ShippingServiceCode == null || trans.ShippingServiceCode == "")
                {
                    Logger.WriteSystemLog("No shipping service code.");
                    return(false);
                }

                InventoryItemType item = ItemDAL.GetItemBySKU(trans.ItemSKU);
                if (item == null)
                {
                    Logger.WriteSystemLog("Cannot get item");
                    return(false);
                }

                worksheet.Cells[curRow, 1] = "";                          // "客户单号"
                worksheet.Cells[curRow, 2] = "";                          // "服务商单号"
                worksheet.Cells[curRow, 3] = trans.ShippingServiceCode;   // "运输方式"
                worksheet.Cells[curRow, 4] = trans.BuyerCountry;          // "目的国家"
                worksheet.Cells[curRow, 5] = "";                          //EbayConstants.SenderCompanyName; // "寄件人公司名"

                worksheet.Cells[curRow, 6]  = "";                         // EbayConstants.SenderName; // "寄件人姓名"
                worksheet.Cells[curRow, 7]  = "";                         // EbayConstants.SenderAddress; // "寄件人地址"
                worksheet.Cells[curRow, 8]  = "";                         // EbayConstants.SenderPhone; // "寄件人电话"
                worksheet.Cells[curRow, 9]  = "";                         //EbayConstants.SenderPostalCode; // "寄件人邮编"
                worksheet.Cells[curRow, 10] = "";                         //EbayConstants.SenderFax; //"寄件人传真"

                worksheet.Cells[curRow, 11] = trans.BuyerCompanyName;     // "收件人公司名"
                worksheet.Cells[curRow, 12] = trans.BuyerName;            // "收件人姓名"
                worksheet.Cells[curRow, 13] = trans.BuyerStateOrProvince; // "州 \ 省"
                worksheet.Cells[curRow, 14] = trans.BuyerCity;            // "城市"

                // 4PX联邮通挂号/平邮地址不能超过60
                if (trans.ShippingServiceCode == "A6" || trans.ShippingServiceCode == "A7")
                {
                    worksheet.Cells[curRow, 15] = trans.BuyerAddressCompact; //"联系地址"
                }
                else
                {
                    worksheet.Cells[curRow, 15] = trans.BuyerAddress; //"联系地址"
                }

                if (trans.BuyerTel != "Invalid Request")
                {
                    worksheet.Cells[curRow, 16] = trans.BuyerTel; // "收件人电话"
                }
                else
                {
                    worksheet.Cells[curRow, 16] = "";                                                      // "收件人电话"
                }
                worksheet.Cells[curRow, 17] = trans.BuyerMail;                                             //"收件人邮箱"
                worksheet.Cells[curRow, 18] = trans.BuyerPostalCode;                                       //"收件人邮编"
                worksheet.Cells[curRow, 19] = "";                                                          //"收件人传真"
                worksheet.Cells[curRow, 20] = trans.BuyerId;                                               //"买家ID"

                worksheet.Cells[curRow, 21] = "";                                                          // trans.EbayTransactionId; // "交易ID"
                worksheet.Cells[curRow, 22] = "";                                                          // "保险类型"
                worksheet.Cells[curRow, 23] = "";                                                          //"保险价值"
                worksheet.Cells[curRow, 24] = "";                                                          // "订单备注";
                worksheet.Cells[curRow, 25] = item.ItemCustomName;                                         // "海关报关品名1"

                worksheet.Cells[curRow, 26] = string.Format("{0}x{1}", trans.SaleQuantity, item.ItemName); // "配货信息1"
                worksheet.Cells[curRow, 27] = item.ItemCustomCost;                                         // "申报价值1"
                worksheet.Cells[curRow, 28] = trans.SaleQuantity;                                          // "申报品数量1"
                worksheet.Cells[curRow, 29] = "";                                                          // "配货备注1"

                curRow++;
            }

            workbook.Saved = true;
            workbook.SaveAs(filePath);

            if (workbook != null)
            {
                workbook.Close();
            }
            if (excelApp != null)
            {
                excelApp.Quit();
            }

            return(true);
        }
Beispiel #18
0
        public static int InsertOneItem(InventoryItemType item)
        {
            string itemSKU = item.ItemSKU;

            if (itemSKU == null || itemSKU.Trim() == "")
            {
                return(-1);
            }

            // We should ensure the item SKU is unique, this is our bottom line!!!
            InventoryItemType existedItemWithSameSKU = GetItemBySKU(itemSKU);

            if (existedItemWithSameSKU != null)
            {
                return(-1);
            }

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Insert into [Item] (CategoryId, ItemName, ItemSKU, ItemImagePath,"
                              + " ItemStockShresholdNum, ItemStockNum, ItemSourcingInfo, ItemCost, ItemWeight, "
                              + " ItemCustomName, ItemCustomWeight, ItemCustomCost, ItemAddDateTime, "
                              + " IsGroupItem, SubItemSKUs, ItemSourcingURL, ItemDispatchTips, ItemNote) values ("
                              + " @CategoryId, @ItemName, @ItemSKU, @ItemImagePath, "
                              + " @ItemStockShresholdNum, @ItemStockNum, @ItemSourcingInfo, @ItemCost, @ItemWeight, "
                              + " @ItemCustomName, @ItemCustomWeight, @ItemCustomCost, @ItemAddDateTime, "
                              + " @IsGroupItem, @SubItemSKUs, @ItemSourcingURL, @ItemDispatchTips, @ItemNote)";

            DataFactory.AddCommandParam(cmd, "@CategoryId", DbType.Int32, item.CategoryId);
            DataFactory.AddCommandParam(cmd, "@ItemName", DbType.String, GetDefaultValue(item.ItemName));

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.Int32, GetDefaultValue(item.ItemSKU));
            DataFactory.AddCommandParam(cmd, "@ItemImagePath", DbType.String, item.ItemImagePath);

            DataFactory.AddCommandParam(cmd, "@ItemStockShresholdNum", DbType.Int32, item.ItemStockShresholdNum);
            DataFactory.AddCommandParam(cmd, "@ItemStockNum", DbType.Int32, item.ItemStockNum);

            DataFactory.AddCommandParam(cmd, "@ItemSourcingInfo", DbType.String, GetDefaultValue(item.ItemSourcingInfo));
            DataFactory.AddCommandParam(cmd, "@ItemCost", DbType.Double, item.ItemCost);

            DataFactory.AddCommandParam(cmd, "@ItemWeight", DbType.Double, item.ItemWeight);
            DataFactory.AddCommandParam(cmd, "@ItemCustomName", DbType.String, GetDefaultValue(item.ItemCustomName));

            DataFactory.AddCommandParam(cmd, "@ItemCustomWeight", DbType.Double, item.ItemCustomWeight);
            DataFactory.AddCommandParam(cmd, "@ItemCustomCost", DbType.Double, item.ItemCustomCost);

            DataFactory.AddCommandParam(cmd, "@ItemAddDateTime", DbType.DateTime, item.ItemAddDateTime.ToString());

            DataFactory.AddCommandParam(cmd, "@IsGroupItem", DbType.Boolean, item.IsGroupItem);
            DataFactory.AddCommandParam(cmd, "@SubItemSKUs", DbType.String, GetDefaultValue(item.SubItemSKUs));

            DataFactory.AddCommandParam(cmd, "@ItemSourcingURL", DbType.String, StringUtil.GetSafeString(item.ItemSourcingURL));
            DataFactory.AddCommandParam(cmd, "@ItemDispatchTips", DbType.String, "");
            DataFactory.AddCommandParam(cmd, "@ItemNote", DbType.String, StringUtil.GetSafeString(item.ItemNote));

            int newItemId = 0;

            try
            {
                if (DataFactory.DbConnection.State == ConnectionState.Closed)
                {
                    DataFactory.DbConnection.Open();
                }
                cmd.ExecuteNonQuery();

                IDbCommand cmdNewID = DataFactory.CreateCommand("SELECT @@IDENTITY");
                // Retrieve the Autonumber and store it in the CategoryID column.
                object obj = cmdNewID.ExecuteScalar();
                Int32.TryParse(obj.ToString(), out newItemId);
            }
            catch (DataException)
            {
                // Write to log here.
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                {
                    DataFactory.DbConnection.Close();
                }
            }

            return(newItemId);
        }