Example #1
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);
        }
        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);
        }
        private static ItemStockInNoteType GetItemStockInNoteFromDataRow(DataRow dr)
        {
            ItemStockInNoteType note = new ItemStockInNoteType();

            note.NoteId         = StringUtil.GetSafeInt(dr["NoteId"]);
            note.ItemSKU        = StringUtil.GetSafeString(dr["ItemSKU"]);
            note.ItemTitle      = StringUtil.GetSafeString(dr["ItemTitle"]);
            note.SourcingNoteId = StringUtil.GetSafeString(dr["SourcingNoteId"]);
            note.StockInNum     = StringUtil.GetSafeInt(dr["StockInNum"]);
            note.StockInDate    = StringUtil.GetSafeDateTime(dr["StockInDate"]);
            note.Comment        = StringUtil.GetSafeString(dr["Comment"]);
            return(note);
        }
        public static bool ModifyOneItemStockInNote(ItemStockInNoteType note)
        {
            bool result = false;

            if (note == null || note.NoteId <= 0)
            {
                return(false);
            }

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Update [ItemStockInNote] set ItemSKU=@ItemSKU, ItemTitle=@ItemTitle, SourcingNoteId=@SourcingNoteId, "
                              + "StockInNum=@StockInNum, StockInDate=@StockInDate, Comment=@Comment where NoteId=@NoteId";

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, note.ItemSKU);
            DataFactory.AddCommandParam(cmd, "@ItemTitle", DbType.String, note.ItemTitle);
            DataFactory.AddCommandParam(cmd, "@SourcingNoteId", DbType.String, note.SourcingNoteId);
            DataFactory.AddCommandParam(cmd, "@StockInNum", DbType.Int32, note.StockInNum);
            DataFactory.AddCommandParam(cmd, "@StockInDate", DbType.DateTime, note.StockInDate);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, note.Comment);

            DataFactory.AddCommandParam(cmd, "@NoteId", DbType.Int32, note.NoteId);

            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);
        }
Example #5
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();
        }
        public static bool DeleteOneItemStockInNote(String noteId)
        {
            bool result = false;

            ItemStockInNoteType note = ItemStockInNoteDAL.GetOneItemStockInNote(noteId);

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

            String sql = string.Format("delete from [ItemStockInNote] where NoteId={0}", noteId);

            DataFactory.ExecuteSql(sql);
            result = true;

            return(result);
        }
        public static int InsertOneItemStockInNote(ItemStockInNoteType note)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Insert into [ItemStockInNote] (ItemSKU, ItemTitle, SourcingNoteId, StockInNum, StockInDate, Comment) values"
                              + "(@ItemSKU, @ItemTitle, @SourcingNoteId, @StockInNum, @StockInDate, @Comment)";

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, note.ItemSKU);
            DataFactory.AddCommandParam(cmd, "@ItemTitle", DbType.String, note.ItemTitle);
            DataFactory.AddCommandParam(cmd, "@SourcingNoteId", DbType.String, note.SourcingNoteId);
            DataFactory.AddCommandParam(cmd, "@StockInNum", DbType.Int32, note.StockInNum);
            DataFactory.AddCommandParam(cmd, "@StockInDate", DbType.DateTime, note.StockInDate.ToShortDateString());
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, note.Comment);

            int newId = 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 newId);
            }
            catch (DataException)
            {
                // Write to log here.
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                {
                    DataFactory.DbConnection.Close();
                }
            }

            return(newId);
        }
        public static int InsertOneItemStockInNote(ItemStockInNoteType note)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);
            cmd.CommandText = @"Insert into [ItemStockInNote] (ItemSKU, ItemTitle, SourcingNoteId, StockInNum, StockInDate, Comment) values"
                    + "(@ItemSKU, @ItemTitle, @SourcingNoteId, @StockInNum, @StockInDate, @Comment)";

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, note.ItemSKU);
            DataFactory.AddCommandParam(cmd, "@ItemTitle", DbType.String, note.ItemTitle);
            DataFactory.AddCommandParam(cmd, "@SourcingNoteId", DbType.String, note.SourcingNoteId);
            DataFactory.AddCommandParam(cmd, "@StockInNum", DbType.Int32, note.StockInNum);
            DataFactory.AddCommandParam(cmd, "@StockInDate", DbType.DateTime, note.StockInDate.ToShortDateString());
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, note.Comment);

            int newId = 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 newId);
            }
            catch (DataException)
            {
                // Write to log here.
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                    DataFactory.DbConnection.Close();
            }

            return newId;
        }
 private static ItemStockInNoteType GetItemStockInNoteFromDataRow(DataRow dr)
 {
     ItemStockInNoteType note = new ItemStockInNoteType();
     note.NoteId = StringUtil.GetSafeInt(dr["NoteId"]);
     note.ItemSKU = StringUtil.GetSafeString(dr["ItemSKU"]);
     note.ItemTitle = StringUtil.GetSafeString(dr["ItemTitle"]);
     note.SourcingNoteId = StringUtil.GetSafeString(dr["SourcingNoteId"]);
     note.StockInNum = StringUtil.GetSafeInt(dr["StockInNum"]);
     note.StockInDate = StringUtil.GetSafeDateTime(dr["StockInDate"]);
     note.Comment = StringUtil.GetSafeString(dr["Comment"]);
     return note;
 }
        public static bool ModifyOneItemStockInNote(ItemStockInNoteType note)
        {
            bool result = false;

            if (note == null || note.NoteId <= 0)
                return false;

            IDbCommand cmd = DataFactory.CreateCommand(null);
            cmd.CommandText = @"Update [ItemStockInNote] set ItemSKU=@ItemSKU, ItemTitle=@ItemTitle, SourcingNoteId=@SourcingNoteId, "
                    + "StockInNum=@StockInNum, StockInDate=@StockInDate, Comment=@Comment where NoteId=@NoteId";

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, note.ItemSKU);
            DataFactory.AddCommandParam(cmd, "@ItemTitle", DbType.String, note.ItemTitle);
            DataFactory.AddCommandParam(cmd, "@SourcingNoteId", DbType.String, note.SourcingNoteId);
            DataFactory.AddCommandParam(cmd, "@StockInNum", DbType.Int32, note.StockInNum);
            DataFactory.AddCommandParam(cmd, "@StockInDate", DbType.DateTime, note.StockInDate);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, note.Comment);

            DataFactory.AddCommandParam(cmd, "@NoteId", DbType.Int32, note.NoteId);

            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;
        }