Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            dtgridList = (DataTable)ViewState["dtgridList"];
            string users = Session["id"].ToString();
            decimal totalamt = 0;
            try
            {
                foreach (DataRow dr in dtgridList.Rows)
                {
                    totalamt = totalamt + decimal.Parse(dr["Amount"].ToString());
                }
                FrameWork.PurchaseOrders PRO = new FrameWork.PurchaseOrders();
                FrameWork.PurchaseOrderDetails PROsub = new PurchaseOrderDetails();
                busPurchaseOrder busPRO = new busPurchaseOrder();
                PRO.SupplierID = int.Parse(this.drpSupplier.SelectedValue);
                PRO.CreatedById = int.Parse(users);
                if (this.txtDateNeeded.Text.Trim() != string.Empty)
                {
                    PRO.ExpectedDate = DateTime.Parse(this.txtDateNeeded.Text);
                }
                else
                {
                    PRO.ExpectedDate = DateTime.Parse("01/01/1900");
                }

                PRO.PaymentAmount = totalamt;

                string x = busPRO.insertPO(PRO);
                foreach (DataRow dr in dtgridList.Rows)
                {
                    PROsub.PurchaseOrderID = int.Parse(x);
                    PROsub.Quantity = Single.Parse(dr["Quantity"].ToString());
                    PROsub.UnitCost = decimal.Parse(dr["UnitPrice"].ToString());
                    PROsub.ProductID = int.Parse(dr["ProductID"].ToString());

                    busPRO.insertPurchaseOrderDetails(PROsub);
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                this.txtQuantity.Text = string.Empty;
                this.txtUOM.Text = string.Empty;
                this.drpProduct.SelectedValue = "0";
                this.lblDescription.Text = string.Empty;
                this.txtUnitPrice.Text = string.Empty;
                this.drpSupplier.SelectedValue = "0";
                this.txtTerms.Text = string.Empty;
                DataTable ds = new DataTable();
                ds = null;
                this.grdList.DataSource = ds;
                grdList.DataBind();
            }
        }
Esempio n. 2
0
        public string insertPO(PurchaseOrders drsi)
        {
            string Message = string.Empty;
            int result = 0;
            SqlTransaction transaction;

            con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].PurchaseOrders ([SupplierID],[CreatedById],[CreationDate],[ExpectedDate],[PaymentAmount],[IsCompleted],[IsSubmitted],[IsNew]) VALUES (@SupplierID,@CreatedById,getdate(),@ExpectedDate,@PaymentAmount,@IsCompleted,@IsSubmitted,@IsNew)", con);
            cmd.Parameters.AddWithValue("@SupplierID", drsi.SupplierID);
            cmd.Parameters.AddWithValue("@CreatedById", drsi.CreatedById);
            cmd.Parameters.AddWithValue("@ExpectedDate", drsi.ExpectedDate);
            cmd.Parameters.AddWithValue("@PaymentAmount", drsi.PaymentAmount);
            cmd.Parameters.AddWithValue("@IsCompleted",1);
            cmd.Parameters.AddWithValue("@IsSubmitted", 1);
            cmd.Parameters.AddWithValue("@IsNew",1);
            transaction = con.BeginTransaction();
            cmd.Transaction = transaction;
            //cmd.Parameters.AddWithValue("@OrderBy", drsi.OrderBy);
            //cmd.Parameters.AddWithValue("@CheckBy", drsi.CheckBy != null ? drsi.CheckBy : string.Empty);
            try
            {
                result = cmd.ExecuteNonQuery();
                transaction.Commit();
            }
            catch (Exception ex)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    // This catch block will handle any errors that may have occurred
                    // on the server that would cause the rollback to fail, such as
                    // a closed connection.
                    Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                    Console.WriteLine("  Message: {0}", ex2.Message);
                }
            }
            con.Close();
            string query = "select top 1 ID from [PurchaseOrders] order by id desc";
            DataTable dt = new DataTable("Customer");
            dt.Clear();
            dt = DataAccess.DBAdapter.GetRecordSet(query);

            if (dt.Rows.Count > 0)
            {
                Message = dt.Rows[0]["ID"].ToString();
            }
            return Message;
        }
Esempio n. 3
0
        public FrameWork.PurchaseOrders[] allPO()
        {
            string query = "SELECT a.[ID] ,b.[Company],b.[Address],[CreationDate],SupplierID, [ExpectedDate],[PaymentAmount],b.[TIN],b.[EmailAddress],a.[CreatedById],a.[ClosedById],b.[BusinessPhone], c.FullName  FROM [dbo].PurchaseOrders a inner join [dbo].[Suppliers] b on a.SupplierID = b.ID inner join [dbo].Employees c on a.CreatedById = c.id order by a.id asc";
            DataTable table = new DataTable();

            table = DataAccess.DBAdapter.GetRecordSet(query);
            FrameWork.PurchaseOrders[] dec = new FrameWork.PurchaseOrders[table.Rows.Count];

            for (int i = 0; i < table.Rows.Count; i++)
            {
                dec[i] = new FrameWork.PurchaseOrders(table.Rows[i]);
            }

            return dec;
        }