Exemple #1
0
        private void buttonFinishEditing_Click(object sender, EventArgs e)
        {
            double           totalFee = 0.0;
            SourcingNoteType note     = GetSourcingNoteFromUI(out totalFee);

            if (note == null)
            {
                return;
            }

            if (mEditMode == EditMode.CreateNew)
            {
                int newNoteId = SourcingNoteDAL.InsertOneSourcingNote(note);
                if (newNoteId > 0)
                {
                    MessageBox.Show("创建采购单成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("创建采购单失败", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (SourcingNoteDAL.ModifyOneSourcingNote(note))
                {
                    MessageBox.Show("修改采购单成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("创建采购单失败", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #2
0
        private void ToolStripMenuItemEditNote_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection rows = this.pagedDgvSourcingNote.DgvData.SelectedRows;

            if (rows == null || rows.Count != 1)
            {
                return;
            }

            DataGridViewRow row = rows[0];

            if (row == null)
            {
                return;
            }

            int noteId            = StringUtil.GetSafeInt(row.Cells[0].Value);
            SourcingNoteType note = SourcingNoteDAL.GetSourcingNoteById(noteId);

            if (note == null)
            {
                return;
            }

            FrmEditSourcingNote frm = new FrmEditSourcingNote(note);

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

            this.pagedDgvSourcingNote.LoadData();
        }
        public FrmEditSourcingNote(SourcingNoteType sourcingNote)
        {
            InitializeComponent();

            mEditMode = EditMode.EditExisting;

            mSourcingNote = sourcingNote;
        }
Exemple #4
0
        public FrmEditSourcingNote(SourcingNoteType sourcingNote)
        {
            InitializeComponent();

            mEditMode = EditMode.EditExisting;

            mSourcingNote = sourcingNote;
        }
        public static bool ModifyOneSourcingNote(SourcingNoteType note)
        {
            bool result = false;

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

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Update [SourcingNote] set SupplierId=@SupplierId, ItemSkuList=@ItemSkuList,"
                              + "ItemNumList=@ItemNumList, ItemPriceList=@ItemPriceList, ExtraFee=@ExtraFee,"
                              + "ShippingFee=@ShippingFee, TotalFee=@TotalFee, Comment=@Comment, SourcingDate=@SourcingDate where SourcingId=@SourcingId";

            DataFactory.AddCommandParam(cmd, "@SupplierId", DbType.Int32, note.SupplierId);
            DataFactory.AddCommandParam(cmd, "@ItemSkuList", DbType.String, note.ItemSkuList);
            DataFactory.AddCommandParam(cmd, "@ItemNumList", DbType.String, note.ItemNumList);
            DataFactory.AddCommandParam(cmd, "@ItemPriceList", DbType.String, note.ItemPriceList);
            DataFactory.AddCommandParam(cmd, "@ExtraFee", DbType.Double, note.ExtraFee);
            DataFactory.AddCommandParam(cmd, "@ShippingFee", DbType.Double, note.ShippingFee);
            DataFactory.AddCommandParam(cmd, "@TotalFee", DbType.Double, note.TotalFee);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, note.Comment);
            DataFactory.AddCommandParam(cmd, "@SourcingDate", DbType.DateTime, note.SourcingDate);

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

            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);
        }
        public static int InsertOneSourcingNote(SourcingNoteType note)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Insert into [SourcingNote] (SupplierId, ItemSkuList, ItemNumList,"
                              + "ItemPriceList, ExtraFee, ShippingFee, TotalFee, Comment, SourcingDate) values"
                              + "(@SupplierId, @ItemSkuList, @ItemNumList,"
                              + "@ItemPriceList, @ExtraFee, @ShippingFee, @TotalFee, @Comment, @SourcingDate)";

            DataFactory.AddCommandParam(cmd, "@SupplierId", DbType.Int32, note.SupplierId);
            DataFactory.AddCommandParam(cmd, "@ItemSkuList", DbType.String, note.ItemSkuList);
            DataFactory.AddCommandParam(cmd, "@ItemNumList", DbType.String, note.ItemNumList);
            DataFactory.AddCommandParam(cmd, "@ItemPriceList", DbType.String, note.ItemPriceList);
            DataFactory.AddCommandParam(cmd, "@ExtraFee", DbType.Double, note.ExtraFee);
            DataFactory.AddCommandParam(cmd, "@ShippingFee", DbType.Double, note.ShippingFee);
            DataFactory.AddCommandParam(cmd, "@TotalFee", DbType.Double, note.TotalFee);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, note.Comment);
            // CAUTION: we need to convert note.SourcingDate to string otherwise we will meet with failure.
            DataFactory.AddCommandParam(cmd, "@SourcingDate", DbType.DateTime, note.SourcingDate.ToShortDateString());

            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 SourcingNoteType GetSourcingNoteFromDataRow(DataRow dr)
        {
            SourcingNoteType note = new SourcingNoteType();

            note.SourcingId    = StringUtil.GetSafeInt(dr["SourcingId"]);
            note.SupplierId    = StringUtil.GetSafeInt(dr["SupplierId"]);
            note.ItemSkuList   = StringUtil.GetSafeString(dr["ItemSkuList"]);
            note.ItemNumList   = StringUtil.GetSafeString(dr["ItemNumList"]);
            note.ItemPriceList = StringUtil.GetSafeString(dr["ItemPriceList"]);
            note.ExtraFee      = StringUtil.GetSafeDouble(dr["ExtraFee"]);
            note.ShippingFee   = StringUtil.GetSafeDouble(dr["ShippingFee"]);
            note.TotalFee      = StringUtil.GetSafeDouble(dr["TotalFee"]);
            note.Comment       = StringUtil.GetSafeString(dr["Comment"]);
            note.SourcingDate  = StringUtil.GetSafeDateTime(dr["SourcingDate"]);
            return(note);
        }
        public static bool DeleteOneSourcingNote(int noteId)
        {
            bool result = false;

            SourcingNoteType note = GetSourcingNoteById(noteId);

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

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

            DataFactory.ExecuteSql(sql);
            result = true;

            return(result);
        }
        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;
        }
Exemple #10
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);
        }