Exemplo n.º 1
0
        private void InsertRecord()
        {
            using (var Connection = new SqlConnection(SalesCenterConfiguration.ConnectionString))
            {
                string InsertString =
                    "INSERT INTO [Quote_Item] ([estItemID], [quoteRevID], [qiPrintOrder], [quoteOption], [supplyType], [qiItemTitle], [qiDescription], [qiAmount], [qiUnitPrice], [qiQty], [recordType], [qiQtyPc],[Requirement],[Position], [quoteOptionText], [qiAmountText]) VALUES (@estItemID, @quoteRevID, @qiPrintOrder, @quoteOption, @supplyType, @qiItemTitle, @qiDescription, @qiAmount, @qiUnitPrice, @qiQty, @recordType,@qiQtyPc, @Requirement, @Position, @quoteOptionText, @qiAmountText)";

                // Create the command and set its properties.
                var InsertCommand = new SqlCommand(InsertString, Connection);
                try
                {
                    Connection.Open();

                    //[Quote_Item] ([estItemID], [quoteRevID], [qiPrintOrder], [quoteOption], [supplyType], [qiItemTitle], [qiDescription], [qiAmount], [qiUnitPrice], [qiQty], [recordType])
                    //Values        (@estItemID, @quoteRevID,  @qiPrintOrder,  @quoteOption,  @supplyType,  @qiItemTitle,  @qiDescription,  @qiAmount,  @qiUnitPrice,  @qiQty,  @recordType)"

                    InsertCommand.Parameters.Add("@estItemID", SqlDbType.Int).Value         = 0;
                    InsertCommand.Parameters.Add("@quoteRevID", SqlDbType.Int).Value        = _myParentID;
                    InsertCommand.Parameters.Add("@qiPrintOrder", SqlDbType.SmallInt).Value =
                        QuoteItemShared.GetMaxItemPrintOrderNumber(_myParentID);
                    InsertCommand.Parameters.Add("@quoteOption", SqlDbType.SmallInt).Value = 1;
                    InsertCommand.Parameters.Add("@supplyType", SqlDbType.SmallInt).Value  =
                        NQuoteSupplyType.SupplyAndInstallation;
                    InsertCommand.Parameters.Add("@qiItemTitle", SqlDbType.NVarChar, 500).Value    = "My Title";
                    InsertCommand.Parameters.Add("@qiDescription", SqlDbType.NVarChar, 1500).Value = "My Description";
                    InsertCommand.Parameters.Add("@qiAmount", SqlDbType.Decimal, 8).Value          = 0;
                    InsertCommand.Parameters.Add("@qiUnitPrice", SqlDbType.Decimal, 8).Value       = 0;
                    InsertCommand.Parameters.Add("@QiQty", SqlDbType.SmallInt).Value  = 1;
                    InsertCommand.Parameters.Add("@recordType", SqlDbType.Char).Value = "Q";

                    InsertCommand.Parameters.Add("@qiQtyPc", SqlDbType.Int).Value          = 0;
                    InsertCommand.Parameters.Add("@Requirement", SqlDbType.Int).Value      = NWorkorderRequirement.Installation;
                    InsertCommand.Parameters.Add("@Position", SqlDbType.NVarChar, 7).Value = "Outdoor";

                    InsertCommand.Parameters.Add("@quoteOptionText", SqlDbType.NVarChar, 300).Value = 1;
                    InsertCommand.Parameters.Add("@qiAmountText", SqlDbType.NVarChar, 300).Value    = 0;

                    InsertCommand.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    string errorLog = ex.Message;
                }
                finally
                {
                    Connection.Close();
                }
            }
        }
Exemplo n.º 2
0
        public void Copy()
        {
            string errorLog        = "Nothing";
            int    NumRowsAffected = 0;

            //2. Define the destination: InvoiceItem
            var    ConnectionSQL    = new SqlConnection(SalesCenterConfiguration.ConnectionString);
            string SqlSelectString1 = "SELECT * FROM [QUOTE_Item] WHERE ([quoteItemID] = @quoteItemID) ";
            var    SelectCommand1   = new SqlCommand(SqlSelectString1, ConnectionSQL);
            var    adapter1         = new SqlDataAdapter(SelectCommand1);

            adapter1.SelectCommand.Parameters.Add("@quoteItemID", SqlDbType.Int).Value = _myID;

            var ds1 = new DataSet();

            ds1.Tables.Clear();

            try
            {
                ConnectionSQL.Open();
                NumRowsAffected = adapter1.Fill(ds1, "t1");
                if (NumRowsAffected != 0)
                {
                    //Destination
                    //3. Copy
                    int     itemIndex = ds1.Tables["t1"].Columns.Count;
                    DataRow row       = ds1.Tables["t1"].Rows[0];
                    DataRow rowNew    = ds1.Tables["t1"].NewRow();
                    int     i         = 0;

                    for (i = 1; i <= itemIndex - 1; i++)
                    {
                        rowNew[i] = row[i];
                    }

                    int pn = Convert.ToInt32(rowNew["qiPrintOrder"]);
                    rowNew["QuoteOption"] = QuoteItemShared.GetMaxOptionNumberOfOneItem(_myParentID, pn);
                    rowNew["isFinal"]     = false;

                    rowNew["qiAmountText"]    = rowNew["qiAmount"];
                    rowNew["quoteOptionText"] = rowNew["quoteOption"];

                    ds1.Tables["t1"].Rows.Add(rowNew);

                    //4. Write ds2,  back to DB

                    var cb = new SqlCommandBuilder(adapter1);
                    adapter1        = cb.DataAdapter;
                    NumRowsAffected = adapter1.Update(ds1, "t1");

                    _newID = SqlCommon.GetNewlyInsertedRecordID("Quote_Item");
                }
            }
            catch (SqlException ex)
            {
                errorLog = ex.Message;
            }
            finally
            {
                ConnectionSQL.Close();
            }
        }