Пример #1
0
        private void buttonFinishEditingSupplier_Click(object sender, EventArgs e)
        {
            SupplierType supplier = null;

            supplier = GetSupplierInfoFromUI();

            if (mEditMode == EditMode.CreateNew)
            {
                int newId = SupplierDAL.InsertOneSupplier(supplier);
                if (newId > 0)
                {
                    MessageBox.Show("创建供应商成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("创建供应商失败", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (mEditMode == EditMode.EditExsiting)
            {
                supplier.SupplierID = mSupplierId;
                if (SupplierDAL.ModifyOneSupplier(supplier))
                {
                    MessageBox.Show("修改供应商成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("修改供应商失败", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.Close();
            }
        }
Пример #2
0
        private void LoadItemSuppliers(int itemId)
        {
            mItemSuppliersTbl.Clear();

            DataTable dtSuppliers = ItemSupplierDAL.GetAllItemSuppliersByItemId(itemId);

            foreach (DataRow row in dtSuppliers.Rows)
            {
                int          supplierId = StringUtil.GetSafeInt(row["SupplierId"]);
                SupplierType supplier   = SupplierDAL.GetSupplierById(supplierId);
                if (supplier == null)
                {
                    continue;
                }
                DataRow rowLoc = mItemSuppliersTbl.NewRow();
                rowLoc["SupplierId"]   = supplierId;
                rowLoc["SupplierName"] = supplier.SupplierName;
                rowLoc["URL"]          = StringUtil.GetSafeString(row["SouringURL"]);
                rowLoc["Price"]        = StringUtil.GetSafeDouble(row["Price"]);
                rowLoc["ShippingFee"]  = StringUtil.GetSafeDouble(row["ShippingFee"]);
                rowLoc["Comment"]      = StringUtil.GetSafeString(row["Comment"]);
                mItemSuppliersTbl.Rows.Add(rowLoc);
            }

            this.dgvItemSuppliers.DataSource = mItemSuppliersTbl;
        }
Пример #3
0
        private SupplierType GetSupplierInfoFromUI()
        {
            SupplierType supplier = new SupplierType();

            String supplierName  = this.textBoxSupplierName.Text.Trim();
            String supplierTel   = this.textBoxSupplierTel.Text.Trim();
            String supplierLink1 = this.textBoxSupplierLink1.Text.Trim();
            String supplierLink2 = this.textBoxSupplierLink2.Text.Trim();
            String supplierLink3 = this.textBoxSupplierLink3.Text.Trim();
            String comment       = this.textBoxSupplierComment.Text.Trim();

            if (supplierName == "")
            {
                MessageBox.Show("供应商名称不能为空", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            supplier.SupplierName  = supplierName;
            supplier.SupplierTel   = supplierTel;
            supplier.SupplierLink1 = supplierLink1;
            supplier.SupplierLink2 = supplierLink2;
            supplier.SupplierLink3 = supplierLink3;
            supplier.Comment       = comment;
            return(supplier);
        }
Пример #4
0
        private void ToolStripMenuItemDelSupplier_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确认刪除该供应商么?\r\n删除前,必须删除所有该供应商的采购单。",
                                "确认发货?",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            // Check if any sourcing notes related to this supplier, if so, disallow delete.
            // [ZHI_TODO]

            int rowIdx     = this.pagedDgvSupplier.DgvData.CurrentRow.Index;
            int supplierId = StringUtil.GetSafeInt(this.pagedDgvSupplier.DgvData.Rows[rowIdx].Cells[0].Value.ToString());

            SupplierType supplier = SupplierDAL.GetSupplierById(supplierId);

            if (supplier == null)
            {
                return;
            }

            SupplierDAL.DeleteOneSupplier(supplierId);
            MessageBox.Show(String.Format("删除供应商成功!", supplier.SupplierName),
                            "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.pagedDgvSupplier.LoadData();
        }
Пример #5
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;
        }
Пример #6
0
        private void buttonSelectSupplier_Click(object sender, EventArgs e)
        {
            FrmSupplierList frmSupplierList = new FrmSupplierList(SupplierDlgMode.SelectSupplier);

            frmSupplierList.ShowDialog();

            if (frmSupplierList.mSelectedSupplier != null)
            {
                mSupplier = frmSupplierList.mSelectedSupplier;
                this.textBoxSupplier.Text = mSupplier.SupplierName;
            }
        }
Пример #7
0
        private static SupplierType GetSupplierFromDataRow(DataRow dr)
        {
            SupplierType supplier = new SupplierType();

            supplier.SupplierID    = StringUtil.GetSafeInt(dr["SupplierID"]);
            supplier.SupplierName  = StringUtil.GetSafeString(dr["SupplierName"]);
            supplier.SupplierTel   = StringUtil.GetSafeString(dr["SupplierTel"]);
            supplier.SupplierLink1 = StringUtil.GetSafeString(dr["SupplierLink1"]);
            supplier.SupplierLink2 = StringUtil.GetSafeString(dr["SupplierLink2"]);
            supplier.SupplierLink3 = StringUtil.GetSafeString(dr["SupplierLink3"]);
            supplier.Comment       = StringUtil.GetSafeString(dr["Comment"]);

            return(supplier);
        }
Пример #8
0
        void DgvData_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            foreach (DataGridViewRow row in pagedDgvSourcingNote.DgvData.Rows)
            {
                int          supplierId = StringUtil.GetSafeInt(row.Cells[1].Value);
                SupplierType supplier   = SupplierDAL.GetSupplierById(supplierId);

                if (supplier == null)
                {
                    continue;
                }

                row.Cells[2].Value = supplier.SupplierName;
            }
        }
Пример #9
0
        public static bool ModifyOneSupplier(SupplierType supplier)
        {
            bool result = false;

            if (supplier == null || supplier.SupplierID <= 0)
            {
                return(false);
            }

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Update [Supplier] set SupplierName=@SupplierName, SupplierTel=@SupplierTel,"
                              + "SupplierLink1=@SupplierLink1, SupplierLink2=@SupplierLink2, SupplierLink3=@SupplierLink3,"
                              + "Comment=@Comment where SupplierId=@SupplierId";

            DataFactory.AddCommandParam(cmd, "@SupplierName", DbType.String, supplier.SupplierName);
            DataFactory.AddCommandParam(cmd, "@SupplierTel", DbType.String, supplier.SupplierTel);
            DataFactory.AddCommandParam(cmd, "@SupplierLink1", DbType.String, supplier.SupplierLink1);
            DataFactory.AddCommandParam(cmd, "@SupplierLink2", DbType.String, supplier.SupplierLink2);
            DataFactory.AddCommandParam(cmd, "@SupplierLink3", DbType.String, supplier.SupplierLink3);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, supplier.Comment);

            DataFactory.AddCommandParam(cmd, "@SupplierId", DbType.Int32, supplier.SupplierID);

            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);
        }
Пример #10
0
        private void ShowSupplierData()
        {
            SupplierType supplier = SupplierDAL.GetSupplierById(mSupplierId);

            if (supplier == null)
            {
                MessageBox.Show("无供应商信息", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.textBoxSupplierName.Text    = supplier.SupplierName;
            this.textBoxSupplierTel.Text     = supplier.SupplierTel;
            this.textBoxSupplierLink1.Text   = supplier.SupplierLink1;
            this.textBoxSupplierLink2.Text   = supplier.SupplierLink2;
            this.textBoxSupplierLink3.Text   = supplier.SupplierLink3;
            this.textBoxSupplierComment.Text = supplier.Comment;
        }
Пример #11
0
        public static int InsertOneSupplier(SupplierType supplier)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Insert into [Supplier] (SupplierName, SupplierTel, SupplierLink1,"
                              + "SupplierLink2, SupplierLink3, Comment) values"
                              + "(@SupplierName, @SupplierTel, @SupplierLink1,"
                              + "@SupplierLink2, @SupplierLink3, @Comment)";

            DataFactory.AddCommandParam(cmd, "@SupplierName", DbType.String, supplier.SupplierName);
            DataFactory.AddCommandParam(cmd, "@SupplierTel", DbType.String, supplier.SupplierTel);
            DataFactory.AddCommandParam(cmd, "@SupplierLink1", DbType.String, supplier.SupplierLink1);
            DataFactory.AddCommandParam(cmd, "@SupplierLink2", DbType.String, supplier.SupplierLink2);
            DataFactory.AddCommandParam(cmd, "@SupplierLink3", DbType.String, supplier.SupplierLink3);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, supplier.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);
        }
Пример #12
0
        public static bool DeleteOneSupplier(int supplierId)
        {
            bool result = false;

            SupplierType supplier = GetSupplierById(supplierId);

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

            String sql = string.Format("delete from [Supplier] where Supplierid={0}", supplierId);

            DataFactory.ExecuteSql(sql);
            result = true;

            return(result);
        }
Пример #13
0
        private void ToolStripMenuItemEditSupplier_Click(object sender, EventArgs e)
        {
            int rowIdx     = this.pagedDgvSupplier.DgvData.CurrentRow.Index;
            int supplierId = StringUtil.GetSafeInt(this.pagedDgvSupplier.DgvData.Rows[rowIdx].Cells[0].Value.ToString());

            SupplierType supplier = SupplierDAL.GetSupplierById(supplierId);

            if (supplier == null)
            {
                return;
            }

            FrmEditSupplier frmEditSupplier = new FrmEditSupplier(supplierId);

            frmEditSupplier.ShowDialog();

            this.pagedDgvSupplier.LoadData();
        }
Пример #14
0
        private void btnFinishSelecting_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = this.pagedDgvSupplier.DgvData.CurrentRow;

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

            int supplierId = StringUtil.GetSafeInt(row.Cells[0].Value);

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

            this.Close();
        }
Пример #15
0
        public static int InsertOneSupplier(SupplierType supplier)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);
            cmd.CommandText = @"Insert into [Supplier] (SupplierName, SupplierTel, SupplierLink1,"
                + "SupplierLink2, SupplierLink3, Comment) values"
                + "(@SupplierName, @SupplierTel, @SupplierLink1,"
                + "@SupplierLink2, @SupplierLink3, @Comment)";

            DataFactory.AddCommandParam(cmd, "@SupplierName", DbType.String, supplier.SupplierName);
            DataFactory.AddCommandParam(cmd, "@SupplierTel", DbType.String, supplier.SupplierTel);
            DataFactory.AddCommandParam(cmd, "@SupplierLink1", DbType.String, supplier.SupplierLink1);
            DataFactory.AddCommandParam(cmd, "@SupplierLink2", DbType.String, supplier.SupplierLink2);
            DataFactory.AddCommandParam(cmd, "@SupplierLink3", DbType.String, supplier.SupplierLink3);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, supplier.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;
        }
Пример #16
0
        private void buttonSelectSupplier_Click(object sender, EventArgs e)
        {
            FrmSupplierList frmSupplierList = new FrmSupplierList(SupplierDlgMode.SelectSupplier);
            frmSupplierList.ShowDialog();

            if (frmSupplierList.mSelectedSupplier != null)
            {
                mSupplier = frmSupplierList.mSelectedSupplier;
                this.textBoxSupplier.Text = mSupplier.SupplierName;
            }
        }
Пример #17
0
        private SupplierType GetSupplierInfoFromUI()
        {
            SupplierType supplier = new SupplierType();

            String supplierName = this.textBoxSupplierName.Text.Trim();
            String supplierTel = this.textBoxSupplierTel.Text.Trim();
            String supplierLink1 = this.textBoxSupplierLink1.Text.Trim();
            String supplierLink2 = this.textBoxSupplierLink2.Text.Trim();
            String supplierLink3 = this.textBoxSupplierLink3.Text.Trim();
            String comment = this.textBoxSupplierComment.Text.Trim();

            if (supplierName == "")
            {
                MessageBox.Show("供应商名称不能为空", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

            supplier.SupplierName = supplierName;
            supplier.SupplierTel = supplierTel;
            supplier.SupplierLink1 = supplierLink1;
            supplier.SupplierLink2 = supplierLink2;
            supplier.SupplierLink3 = supplierLink3;
            supplier.Comment = comment;
            return supplier;
        }
Пример #18
0
        private void btnFinishSelecting_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = this.pagedDgvSupplier.DgvData.CurrentRow;
            if (row == null)
            {
                MessageBox.Show("未选中任何供应商", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int supplierId = StringUtil.GetSafeInt(row.Cells[0].Value);
            mSelectedSupplier = SupplierDAL.GetSupplierById(supplierId);
            if (mSelectedSupplier == null)
            {
                MessageBox.Show("未选中任何供应商", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.Close();
        }
Пример #19
0
        private static SupplierType GetSupplierFromDataRow(DataRow dr)
        {
            SupplierType supplier = new SupplierType();
            supplier.SupplierID = StringUtil.GetSafeInt(dr["SupplierID"]);
            supplier.SupplierName = StringUtil.GetSafeString(dr["SupplierName"]);
            supplier.SupplierTel = StringUtil.GetSafeString(dr["SupplierTel"]);
            supplier.SupplierLink1 = StringUtil.GetSafeString(dr["SupplierLink1"]);
            supplier.SupplierLink2 = StringUtil.GetSafeString(dr["SupplierLink2"]);
            supplier.SupplierLink3 = StringUtil.GetSafeString(dr["SupplierLink3"]);
            supplier.Comment = StringUtil.GetSafeString(dr["Comment"]);

            return supplier;
        }
Пример #20
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;
        }
Пример #21
0
        public static bool ModifyOneSupplier(SupplierType supplier)
        {
            bool result = false;

            if (supplier == null || supplier.SupplierID <= 0)
                return false;

            IDbCommand cmd = DataFactory.CreateCommand(null);
            cmd.CommandText = @"Update [Supplier] set SupplierName=@SupplierName, SupplierTel=@SupplierTel,"
                + "SupplierLink1=@SupplierLink1, SupplierLink2=@SupplierLink2, SupplierLink3=@SupplierLink3,"
                + "Comment=@Comment where SupplierId=@SupplierId";

            DataFactory.AddCommandParam(cmd, "@SupplierName", DbType.String, supplier.SupplierName);
            DataFactory.AddCommandParam(cmd, "@SupplierTel", DbType.String, supplier.SupplierTel);
            DataFactory.AddCommandParam(cmd, "@SupplierLink1", DbType.String, supplier.SupplierLink1);
            DataFactory.AddCommandParam(cmd, "@SupplierLink2", DbType.String, supplier.SupplierLink2);
            DataFactory.AddCommandParam(cmd, "@SupplierLink3", DbType.String, supplier.SupplierLink3);
            DataFactory.AddCommandParam(cmd, "@Comment", DbType.String, supplier.Comment);

            DataFactory.AddCommandParam(cmd, "@SupplierId", DbType.Int32, supplier.SupplierID);

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