protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        LabelIdGot.Text = "";

        DBconnector.Connector.EmployeeType employeeType = DBconnector.Connector.EmployeeType.FullTime;

        string type = (string)Session["timeCardType"];

        if (type == "fulltime")
        {
            employeeType = DBconnector.Connector.EmployeeType.FullTime;
        }
        else if (type == "parttime")
        {
            employeeType = DBconnector.Connector.EmployeeType.PartTime;
        }
        else if (type == "seasonal")
        {
            employeeType = DBconnector.Connector.EmployeeType.Seasonal;
        }

        DBconnector.TimeCard card = new DBconnector.TimeCard();
        card.first = TextBox1.Text;
        card.second = TextBox2.Text;
        card.third = TextBox3.Text;
        card.fourth = TextBox4.Text;
        card.fifth = TextBox5.Text;
        card.six = TextBox6.Text;
        card.seven = TextBox7.Text;
        DBconnector.PieceTimeCard pieceCard = new PieceTimeCard();
        pieceCard.first = "0";
        pieceCard.second = "0";
        pieceCard.third = "0";
        pieceCard.fourth = "0";
        pieceCard.fifth = "0";
        pieceCard.six = "0";
        pieceCard.seven = "0";

        int id = (int)Session["timeCardId"];

        if (this.conn.AddTimeCard(employeeType, id.ToString(), TextBoxDate.Text, card, pieceCard) == "")
        {
            LabelError.Text = "Inserted";

        }
    }
Exemple #2
0
        /// <summary>
        /// add a time card entry
        /// </summary>
        /// <param name="type"></param>
        /// <param name="employeeId"></param>
        /// <param name="startDate"></param>
        /// <param name="card"></param>
        /// <param name="pieceCard"></param>
        /// <returns></returns>
        public string AddTimeCard(EmployeeType type, string employeeId, string startDate,  TimeCard card, PieceTimeCard pieceCard)
        {
            string status = "";

            try
            {
                this.command = new SqlCommand();
                this.command.Connection = this.connection;
                string seasonal = "";

                string table = "";
                string id = "";

                string seasonalPieces = "";

                if (type == EmployeeType.FullTime)
                {
                    table = "FullTimeEmployee";
                    id = "FullTimeID";
                }
                else if (type == EmployeeType.PartTime)
                {
                    table = "PartTimeEmployee";
                    id = "PartTimeID";
                }
                else if (type == EmployeeType.Seasonal)
                {
                    table = "SeasonalEmployee";
                    id = "SeasonalID";

                    seasonal = ",OneSeasonPieces,TwoSeasonPieces, ThreeSeasonPieces,FourSeasonPieces,FiveSeasonPieces,SixSeasonPieces,SevenSeasonPieces";
                    seasonalPieces = "'"+pieceCard.first + "','" + pieceCard.second + "','" + pieceCard.third + "','" + pieceCard.fourth + "','" + pieceCard.fifth + "','" + pieceCard.six + "','" + pieceCard.seven + "'";
                }

                this.command.CommandText = "insert into TimeCard (" + id + ",StartingDate, OneDayHours, TwoDayHours,ThreeDayHours," +
                    "FourDayHours, FiveDayHours, SixDayHours,SevenDayHours" + seasonal + ") Output Inserted.ID values('" + employeeId +
                    "','" + startDate + "','" + card.first + "','" + card.second + "','" + card.third + "','" + card.fourth + "','" + card.fifth + "','" + card.six + "','" + card.seven + "'";
                if (seasonalPieces != "")
                {
                  this.command.CommandText +=  "," +
                       seasonalPieces + ")";
                }
                else
                {
                    this.command.CommandText += ")";
                }

                this.connection.Open();

                int result = (int)this.command.ExecuteScalar();

                this.connection.Close();

                this.InsertIntoAudit("TimeCard", result.ToString(), "inserted", "", ""); ;
            }
            catch (Exception ex)
            {
                status = ex.Message;
                if (this.connection.State != System.Data.ConnectionState.Closed)
                {
                    this.connection.Close();
                }
            }

            return status;
        }