public bool AddUnit(clsUnit info)
        {
            int st = 0;

            try
            {
                using (SqlConnection conn = new SqlConnection(strConn))
                {
                    conn.Open();
                    {
                        using (SqlCommand cmd = new SqlCommand("TMR_USP_AddUnit"))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Connection  = conn;
                            cmd.Parameters.AddWithValue("@UnitID", info.strUnitID);
                            cmd.Parameters.AddWithValue("@Prefix", info.strPrefix);
                            cmd.Parameters.AddWithValue("@Number", info.strNumber);
                            cmd.Parameters.AddWithValue("@ProjectID", info.strProjectID);
                            cmd.Parameters.AddWithValue("@BlockNo", info.strBlockNo);
                            cmd.Parameters.AddWithValue("@StreetNo", info.strStreetNo);
                            cmd.Parameters.AddWithValue("@PlotNo", info.strPlotNo);
                            cmd.Parameters.AddWithValue("@SizeCode", info.strSizeCode);
                            cmd.Parameters.AddWithValue("@UnitCategoryID", info.strUnitCategoryID);
                            cmd.Parameters.AddWithValue("@UnitTypeID", info.strUnitTypeID);
                            cmd.Parameters.AddWithValue("@Status", info.strStatus);

                            cmd.Parameters.AddWithValue("@Area", info.decArea);
                            cmd.Parameters.AddWithValue("@UOMID", info.strUOMID);
                            cmd.Parameters.AddWithValue("@Width", info.decWidth);
                            cmd.Parameters.AddWithValue("@Length", info.decLength);
                            cmd.Parameters.AddWithValue("@RegistrationNo", info.strRegistrationNo);
                            cmd.Parameters.AddWithValue("@Price", info.decPrice);
                            cmd.Parameters.AddWithValue("@Statuscode", (int)info.statuscode);
                            cmd.Parameters.AddWithValue("@ID", info.ID);
                            st = cmd.ExecuteNonQuery();
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex) { }
            if (st > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get Units having status AVailable
        /// </summary>
        /// <param name="strProject"></param>
        /// <param name="strBlock"></param>
        /// <param name="strSizeCode"></param>
        /// <returns></returns>
        public List <clsUnit> GetAvailableUnitsByProjectBlockSizeCode(string strProject, string strBlock, string strSizeCode)
        {
            List <clsUnit> lst = new List <clsUnit>();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand("TMR_USP_GetAvailableUnitsBySizeCode"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = conn;
                    cmd.Parameters.AddWithValue("@ProjectId", strProject);
                    cmd.Parameters.AddWithValue("@BlockNo", strBlock);
                    cmd.Parameters.AddWithValue("@SizeCode", strSizeCode);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var info = new clsUnit();

                        info.strUnitID         = reader["UnitID"].ToString();
                        info.strProjectID      = reader["ProjectID"].ToString();
                        info.strBlockNo        = reader["BlockNo"].ToString();
                        info.strStreetNo       = reader["StreetNo"].ToString();
                        info.strPlotNo         = reader["PlotNo"].ToString();
                        info.strSizeCode       = reader["SizeCode"].ToString();
                        info.strUnitCategoryID = reader["UnitCategoryID"].ToString();
                        info.strUnitTypeID     = reader["UnitTypeID"].ToString();
                        info.strStatus         = reader["Status"].ToString();

                        info.decArea           = Convert.ToDecimal(reader["Area"]);
                        info.strUOMID          = reader["UOMID"].ToString();
                        info.decWidth          = Convert.ToDecimal(reader["Width"]);
                        info.decLength         = Convert.ToDecimal(reader["Length"]);
                        info.decSquareFeet     = Convert.ToDecimal(reader["SquareFeet"]);
                        info.decPrice          = Convert.ToDecimal(reader["Price"]);
                        info.strRegistrationNo = reader["RegistrationNo"].ToString();
                        info.ID = Convert.ToInt32(reader["ID"]);

                        lst.Add(info);
                    }
                    conn.Close();
                }
            }
            return(lst);
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            decimal outResult = 0;
            bool    bResult   = false;

            bResult = decimal.TryParse(txtWidth.Text, out outResult);

            if (bResult == false)
            {
                MessageBox.Show("Please specify a valid width.");
                return;
            }
            bResult = decimal.TryParse(txtArea.Text, out outResult);

            if (bResult == false)
            {
                MessageBox.Show("Please specify a valid area.");
                return;
            }
            bResult = decimal.TryParse(txtLength.Text, out outResult);

            if (bResult == false)
            {
                MessageBox.Show("Please specify a valid length.");
                return;
            }
            bResult = decimal.TryParse(txtPrice.Text, out outResult);

            if (bResult == false)
            {
                MessageBox.Show("Please specify a valid price.");
                return;
            }

            if (cmbProjectID.Text == "")
            {
                MessageBox.Show("Please select a project.");
                return;
            }
            if (cmbBlockID.Text == "")
            {
                MessageBox.Show("Please select a block.");
                return;
            }
            if (cmbUnitType.Text == "")
            {
                MessageBox.Show("Please select a valid category.");
                return;
            }
            if (cmbUnitCategory.Text == "")
            {
                MessageBox.Show("Please select a valid nature.");
                return;
            }
            if (txtUnitID.Text == "")
            {
                MessageBox.Show("Please enter a valid unit id.");
                return;
            }

            if (id == 0)
            {
                txtStatus.Text = "Available";
            }

            bool b = da.GetUnitIDAvailability(txtUnitID.Text);

            if (b == false)
            {
                MessageBox.Show("The unit id has already been used. Please enter a new unit id");
                return;
            }

            clsUnit unit = new clsUnit()
            {
                strUnitTypeID     = cmbUnitType.Text,
                strNumber         = strNumber,
                strPrefix         = strPrefix,
                strRegistrationNo = txtRegistrationNo.Text,
                strBlockNo        = cmbBlockID.Text,
                strProjectID      = cmbProjectID.Text,
                strSizeCode       = cmbSizeCode.Text,
                strStatus         = txtStatus.Text,
                strStreetNo       = txtStreetNo.Text,
                strPlotNo         = txtPlotNo.Text,
                strUnitID         = txtUnitID.Text,
                strUnitCategoryID = cmbUnitCategory.Text,
                decWidth          = Convert.ToDecimal(txtWidth.Text),
                decLength         = Convert.ToDecimal(txtLength.Text),
                strUOMID          = txtUom.Text,
                decPrice          = Convert.ToDecimal(txtPrice.Text),
                decArea           = Convert.ToDecimal(txtArea.Text),


                ID = this.id
            };

            if (this.id == 0)
            {
                unit.statuscode = (int)unitLookupCodes.Available;
            }

            bool result = da.AddUnit(unit);

            LoadGrid();
        }