示例#1
0
        //更改
        private void tsbUpdate_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.Update))
                {
                    SIS.DBClass.DBClassRMADetails DBCSD    = new DBClass.DBClassRMADetails();
                    SIS.Configuration.Items[]     oldItems = null;

                    oldItems = DBCSD.QueryData(txtRMAID.Text);
                    if (oldItems == null)
                    {
                        MessageBox.Show("對不起,資料庫不存在[ " + txtRMAID.Text +
                                        " ]退貨單資料!!(資料不存在)", "資料更新");
                        return;
                    }
                    RunUpdateData(oldItems);
                }
            }
            else
            {
                MessageBox.Show("取消退貨單更新動作!!", "更新退貨單");
            }
        }
示例#2
0
        /// <summary>
        /// 查詢退貨單相關資料
        /// </summary>
        /// <param name="RMAID">傳入退貨單編號</param>
        /// <param name="CRC">傳入存放查詢結果資料的SIS.Configuration.ClsRMAConfig CRC</param>
        /// <returns></returns>
        public bool QueryData(string RMAID, SIS.Configuration.ClsRMAConfig CRC)
        {
            InitDB();
            string selectCmd;

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

            try
            {
                cmd = new SqlCommand(selectCmd, conn);
                dr  = cmd.ExecuteReader();
                if (dr.Read())
                {
                    CRC.RMAID           = RMAID;
                    CRC.RMADate         = dr["RMADate"].ToString();
                    CRC.RMAType         = dr["RMAType"].ToString();
                    CRC.TotalPreTax     = int.Parse(dr["TotalPreTax"].ToString());
                    CRC.Tax             = int.Parse(dr["Tax"].ToString());
                    CRC.TotalAfterTax   = int.Parse(dr["TotalAfterTax"].ToString());
                    CRC.StockIDOrShipID = dr["StockIDOrShipID"].ToString();
                    CRC.BusinessTax     = int.Parse(dr["BusinessTax"].ToString());
                    CRC.AmountPaid      = int.Parse(dr["AmountPaid"].ToString());
                    CRC.UnpaidAmount    = int.Parse(dr["UnpaidAmount"].ToString());
                    CRC.RMAAmount       = int.Parse(dr["RMAAmount"].ToString());
                    CRC.Staff           = dr["Staff"].ToString();
                    CRC.PaymentType     = dr["PaymentType"].ToString();
                    CRC.Notes           = dr["Notes"].ToString();
                    conn.Close();

                    SIS.DBClass.DBClassRMADetails DBRD = new DBClassRMADetails();

                    CRC.RMAItems = DBRD.QueryData(RMAID);
                    if (CRC.RMAItems == null)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    conn.Close();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                conn.Close();
                return(false);
            }
        }
示例#3
0
        /// <summary>
        /// 更新一筆資料
        /// </summary>
        /// <param name="CRC">傳入存放更新資料的SIS.Configuration.ClsRMAConfig</param>
        /// <param name="OLDItems">傳入更新前的商品集合</param>
        /// <returns></returns>
        public bool Update(SIS.Configuration.ClsRMAConfig CRC, SIS.Configuration.Items[] OLDItems)
        {
            InitDB();

            string updateCmd, updateCmd2;

            updateCmd = "UPDATE " + TableName + " SET ";
            updateCmd = updateCmd + " RMAID='" + CRC.RMAID + "',";
            updateCmd = updateCmd + " RMADate='" + CRC.RMADate + "',";
            updateCmd = updateCmd + " RMAType='" + CRC.RMAType + "',";
            updateCmd = updateCmd + " TotalPreTax=" + CRC.TotalPreTax + ",";
            updateCmd = updateCmd + " Tax=" + CRC.Tax + ",";
            updateCmd = updateCmd + " TotalAfterTax=" + CRC.TotalAfterTax + ",";
            updateCmd = updateCmd + " StockIDOrShipID='" + CRC.StockIDOrShipID + "',";
            updateCmd = updateCmd + " BusinessTax=" + CRC.BusinessTax + ",";
            updateCmd = updateCmd + " AmountPaid=" + CRC.AmountPaid + ",";
            updateCmd = updateCmd + " UnpaidAmount=" + CRC.UnpaidAmount + ",";
            updateCmd = updateCmd + " RMAAmount=" + CRC.RMAAmount + ",";
            updateCmd = updateCmd + " Staff='" + CRC.Staff + "',";
            updateCmd = updateCmd + " PaymentType='" + CRC.PaymentType + "',";
            updateCmd = updateCmd + " Notes='" + CRC.Notes + "'";
            updateCmd = updateCmd + " WHERE RMAID='" + CRC.RMAID + "'";

            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.DBClassRMADetails DBCRD        = new DBClassRMADetails();

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

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

                    int nowQuantity = OLDItems[i].Quantity;

                    if (CRC.RMAType == "Customer")
                    {
                        if (nowQuantity < CRC.RMAItems[i].Quantity)
                        {
                            DBCItemsInfo.UpdateInventory(CRC.RMAItems[i].ItemsID, (CRC.RMAItems[i].Quantity - nowQuantity)); //更新商品庫存量
                        }
                        else if (nowQuantity > CRC.RMAItems[i].Quantity)
                        {
                            DBCItemsInfo.UpdateInventory(CRC.RMAItems[i].ItemsID, (CRC.RMAItems[i].Quantity - nowQuantity)); //更新商品庫存量
                        }
                        else if (nowQuantity == CRC.RMAItems[i].Quantity)
                        {
                            //數量一樣不用更新庫存
                        }
                    }
                    else
                    {
                        if (nowQuantity < CRC.RMAItems[i].Quantity)
                        {
                            DBCItemsInfo.UpdateInventory(CRC.RMAItems[i].ItemsID, -(CRC.RMAItems[i].Quantity - nowQuantity)); //更新商品庫存量
                        }
                        else if (nowQuantity > CRC.RMAItems[i].Quantity)
                        {
                            DBCItemsInfo.UpdateInventory(CRC.RMAItems[i].ItemsID, -(CRC.RMAItems[i].Quantity - nowQuantity)); //更新商品庫存量
                        }
                        else if (nowQuantity == CRC.RMAItems[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);
            }
        }