Beispiel #1
0
        //刪除
        private void tsbDelete_Click(object sender, EventArgs e)
        {
            string Msg = "是否要進行出貨單[" + txtShipID.Text + "]刪除動作?\r\n";


            DialogResult DR;

            DR = MessageBox.Show(Msg, "刪除出貨單", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (DR == DialogResult.Yes)
            {
                if (CheckField())
                {
                    SIS.DBClass.DBClassShipDetails DBCSD    = new DBClass.DBClassShipDetails();
                    SIS.Configuration.Items[]      oldItems = null;

                    oldItems = DBCSD.QueryData(txtShipID.Text);
                    if (oldItems == null)
                    {
                        MessageBox.Show("對不起,資料庫不存在[ " + txtShipID.Text +
                                        " ]出貨單資料!!(資料不存在)", "資料刪除");
                        return;
                    }
                    RunDeleteData(oldItems);
                }
            }
            else
            {
                MessageBox.Show("取消出貨單刪除動作!!", "刪除出貨單");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 查詢出貨單相關資料
        /// </summary>
        /// <param name="ShipID">傳入出貨單編號</param>
        /// <param name="CSC">傳入存放查詢結果資料的SIS.Configuration.ClsShipConfig CSC</param>
        /// <returns></returns>
        public bool QueryData(string ShipID, SIS.Configuration.ClsShipConfig CSC)
        {
            InitDB();
            string selectCmd;

            selectCmd = "Select * From " + TableName + " Where ShipID='" + ShipID + "'";

            try
            {
                cmd = new SqlCommand(selectCmd, conn);
                dr  = cmd.ExecuteReader();
                if (dr.Read())
                {
                    CSC.ShipID                 = ShipID;
                    CSC.ShipDate               = dr["ShipDate"].ToString();
                    CSC.TotalPreTax            = int.Parse(dr["TotalPreTax"].ToString());
                    CSC.Tax                    = int.Parse(dr["Tax"].ToString());
                    CSC.TotalAfterTax          = int.Parse(dr["TotalAfterTax"].ToString());
                    CSC.CustomerID             = dr["CustomerID"].ToString();
                    CSC.BusinessTaxShipTaxRate = int.Parse(dr["BusinessTaxShipTaxRate"].ToString());
                    CSC.AmountPaid             = int.Parse(dr["AmountPaid"].ToString());
                    CSC.UnpaidAmount           = int.Parse(dr["UnpaidAmount"].ToString());
                    CSC.ShipStaff              = dr["ShipStaff"].ToString();
                    CSC.PaymentType            = dr["PaymentType"].ToString();
                    CSC.Notes                  = dr["Notes"].ToString();
                    conn.Close();

                    SIS.DBClass.DBClassShipDetails DBSD = new DBClassShipDetails();

                    CSC.ShipItems = DBSD.QueryData(ShipID);
                    if (CSC.ShipItems == null)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    conn.Close();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                conn.Close();
                return(false);
            }
        }
Beispiel #3
0
        //查詢
        private void tsbQuery_Click(object sender, EventArgs e)
        {
            string Msg = "是否要進行退貨單[" + txtRMAID.Text + "]查詢動作?\r\n";


            DialogResult DR;

            DR = MessageBox.Show(Msg, "查詢退貨單", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (DR == DialogResult.Yes)
            {
                if (CheckField(SIS.Configuration.CheckFieldType.Query))
                {
                    SIS.DBClass.DBClassRMAMaster   DBCRM = new DBClass.DBClassRMAMaster();
                    SIS.Configuration.ClsRMAConfig CRC   = new Configuration.ClsRMAConfig();

                    bool result = DBCRM.QueryData(txtRMAID.Text, CRC);
                    if (result)
                    {
                        MessageBox.Show("有找到退貨單號:[" + txtRMAID.Text + "]資料!\r\n是否將退貨單資料載入?", "搜尋結果", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (DR == DialogResult.Yes)
                        {
                            txtRMAID.Text   = CRC.RMAID;
                            dtpRMADate.Text = CRC.RMADate;
                            if (CRC.RMAType == "Customer")
                            {
                                rdoRMAShip.Checked = true;
                            }
                            else
                            {
                                rdoRMAStock.Checked = true;
                            }
                            //rdoRMAShip.Checked = (CRC.RMAType == "Customer") ? true : false;
                            //rdoRMAStock.Checked = (CRC.RMAType == "Manufacturer") ? true : false;
                            txtTotalPreTax.Text     = CRC.TotalPreTax.ToString();
                            txtTax.Text             = CRC.Tax.ToString();
                            txtTotalAfterTax.Text   = CRC.TotalAfterTax.ToString();
                            txtStockIDOrShipID.Text = CRC.StockIDOrShipID;
                            txtBusinessTax.Text     = CRC.BusinessTax.ToString();
                            mtbAmountPaid.Text      = CRC.AmountPaid.ToString();
                            txtUnpaidAmount.Text    = CRC.UnpaidAmount.ToString();
                            mtbRMAAmount.Text       = CRC.RMAAmount.ToString();
                            cboStaff.Text           = CRC.Staff;
                            cboPaymentType.Text     = My.MyMethod.SearchComboBoxItems(cboPaymentType, CRC.PaymentType);
                            rtbNotes.Text           = CRC.Notes;

                            if (dgvRMADetails.Rows.Count >= 1)
                            {
                                btnRemoveItems_Click(sender, e);
                            }

                            DBClass.DBClassShipDetails  DBShip  = new DBClass.DBClassShipDetails();
                            DBClass.DBClassStockDetails DBStock = new DBClass.DBClassStockDetails();

                            for (int i = 0; i < CRC.RMAItems.Length; i++)
                            {
                                var index = dgvRMADetails.Rows.Add();
                                dgvRMADetails.Rows[index].Cells["ItemsID"].Value = CRC.RMAItems[i].ItemsID;
                                dgvRMADetails.Rows[index].Cells["NAME"].Value    = CRC.RMAItems[i].NAME;
                                if (CRC.RMAType == "Customer")
                                {
                                    dgvRMADetails.Rows[index].Cells["Quantity"].Value = DBShip.QueryItemQuantity(CRC.StockIDOrShipID, CRC.RMAItems[i].ItemsID);
                                }
                                else
                                {
                                    dgvRMADetails.Rows[index].Cells["Quantity"].Value = DBStock.QueryItemQuantity(CRC.StockIDOrShipID, CRC.RMAItems[i].ItemsID);
                                }
                                //dgvRMADetails.Rows[index].Cells["Quantity"].Value = CRC.RMAItems[i].Quantity.ToString();
                                dgvRMADetails.Rows[index].Cells["RMAQuantity"].Value = CRC.RMAItems[i].Quantity.ToString();
                                dgvRMADetails.Rows[index].Cells["ItemsUnit"].Value   = CRC.RMAItems[i].ItemsUnit;
                                dgvRMADetails.Rows[index].Cells["Price"].Value       = CRC.RMAItems[i].Price.ToString();
                                dgvRMADetails.Rows[index].Cells["Totals"].Value      = CRC.RMAItems[i].Totals.ToString();
                                dgvRMADetails.Rows[index].Cells["Notes"].Value       = CRC.RMAItems[i].Notes;
                            }
                            getTaxTotals();
                        }
                    }
                    else
                    {
                        MessageBox.Show("沒有找到退貨單號:[" + txtRMAID.Text + "]資料!", "搜尋結果");
                    }
                }
            }
            else
            {
                MessageBox.Show("取消退貨單查詢動作!!", "查詢進貨單");
            }
        }
Beispiel #4
0
        /// <summary>
        /// 更新一筆資料
        /// </summary>
        /// <param name="CSC">傳入存放更新資料的SIS.Configuration.ClsShipConfig</param>
        /// <param name="OLDItems">傳入更新前的商品集合</param>
        /// <returns></returns>
        public bool Update(SIS.Configuration.ClsShipConfig CSC, SIS.Configuration.Items[] OLDItems)
        {
            InitDB();

            string updateCmd, updateCmd2;

            updateCmd = "UPDATE " + TableName + " SET ";
            updateCmd = updateCmd + " ShipID='" + CSC.ShipID + "',";
            updateCmd = updateCmd + " ShipDate='" + CSC.ShipDate + "',";
            updateCmd = updateCmd + " TotalPreTax=" + CSC.TotalPreTax + ",";
            updateCmd = updateCmd + " Tax=" + CSC.Tax + ",";
            updateCmd = updateCmd + " TotalAfterTax=" + CSC.TotalAfterTax + ",";
            updateCmd = updateCmd + " CustomerID='" + CSC.CustomerID + "',";
            updateCmd = updateCmd + " BusinessTaxShipTaxRate=" + CSC.BusinessTaxShipTaxRate + ",";
            updateCmd = updateCmd + " AmountPaid=" + CSC.AmountPaid + ",";
            updateCmd = updateCmd + " UnpaidAmount=" + CSC.UnpaidAmount + ",";
            updateCmd = updateCmd + " ShipStaff='" + CSC.ShipStaff + "',";
            updateCmd = updateCmd + " PaymentType='" + CSC.PaymentType + "',";
            updateCmd = updateCmd + " Notes='" + CSC.Notes + "'";
            updateCmd = updateCmd + " WHERE ShipID='" + CSC.ShipID + "'";

            transaction = conn.BeginTransaction("MyUpdateTransaction");

            try
            {
                cmd             = conn.CreateCommand(); // new SqlCommand(updateCmd, conn);
                cmd.CommandText = updateCmd;
                cmd.Transaction = transaction;
                cmd.ExecuteNonQuery();

                DBClass.DBClassItemsInfo   DBCItemsInfo = new DBClassItemsInfo();
                DBClass.DBClassShipDetails DBCSD        = new DBClassShipDetails();

                for (int i = 0; i < CSC.ShipItems.Length; i++)
                {
                    updateCmd2 = "UPDATE " + TableName2 + " SET ";
                    updateCmd2 = updateCmd2 + " ShipID='" + CSC.ShipID + "',";
                    updateCmd2 = updateCmd2 + " ItemsID='" + CSC.ShipItems[i].ItemsID + "',";
                    updateCmd2 = updateCmd2 + " NAME='" + CSC.ShipItems[i].NAME + "',";
                    updateCmd2 = updateCmd2 + " Quantity=" + CSC.ShipItems[i].Quantity + ",";
                    updateCmd2 = updateCmd2 + " ItemsUnit='" + CSC.ShipItems[i].ItemsUnit + "',";
                    updateCmd2 = updateCmd2 + " SellingPrice=" + CSC.ShipItems[i].Price + ",";
                    updateCmd2 = updateCmd2 + " Totals=" + CSC.ShipItems[i].Totals + ",";
                    updateCmd2 = updateCmd2 + " Notes='" + CSC.ShipItems[i].Notes + "'";
                    updateCmd2 = updateCmd2 + " WHERE ShipID='" + CSC.ShipID + "' And ItemsID='" + CSC.ShipItems[i].ItemsID + "'";

                    cmd.CommandText = updateCmd2;
                    cmd.ExecuteNonQuery();

                    int nowQuantity = OLDItems[i].Quantity;
                    if (nowQuantity < CSC.ShipItems[i].Quantity)
                    {
                        DBCItemsInfo.UpdateInventory(CSC.ShipItems[i].ItemsID, -(CSC.ShipItems[i].Quantity - nowQuantity)); //更新商品庫存量
                    }
                    else if (nowQuantity > CSC.ShipItems[i].Quantity)
                    {
                        DBCItemsInfo.UpdateInventory(CSC.ShipItems[i].ItemsID, -(CSC.ShipItems[i].Quantity - nowQuantity)); //更新商品庫存量
                    }
                    else if (nowQuantity == CSC.ShipItems[i].Quantity)
                    {
                        //數量一樣不用更新庫存
                    }
                }

                transaction.Commit(); //try to Commit above sql command

                conn.Close();
                return(true);
            }
            catch (Exception ex)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    errorMsg = ex2.Message;
                    return(false);
                }
                errorMsg = ex.Message;
                conn.Close();
                return(false);
            }
        }