private string Validate_Lot(CuttingOutStock _CuttingOutStock)
        {
            string message = "";
            bool flag = false;

            // for Lot
            flag = CuttingOutStock_DA.IsLotBeforeOutStock(_CuttingOutStock);

            if (!flag)
            {
                message = "-1";
            }
            return message;
        }
        private void SendNotification(CuttingOutStock _CuttingOutStock, DataTable dt)
        {
            string MessageBody = "Edited By : <b>" + Session["User"].ToString().ToUpper() + "</b><br><br>" + DateTime.UtcNow.AddHours(5) + "<br><h3>Before Edit</h3>";
            string tableStart = "<table style=\" width:100%;border-collapse: collapse;\">";//border: 1px solid #ddd;
            string tableEnd = "</table>";
            string MessageHeader = "<tr>";
            string MessageDataOld = "<tr>";
            string MessageDataNew = "<tr>";

            #region Old Header New

            MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + Convert.ToDateTime(dt.Rows[0]["Date"].ToString()).ToString("MM/dd/yyyy") + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Date" + "</th>";
            MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _CuttingOutStock.Date.ToString("MM/dd/yyyy") + "</td>";

            if (dt.Rows[0]["Company"].ToString() == "")
                MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + "" + "</td>";
            else
                MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + ((DataTable)Company_DA.Get_Company_By_Id(int.Parse(dt.Rows[0]["Company"].ToString()))).Rows[0]["Name"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Company" + "</th>";
            if (_CuttingOutStock.Company == null)
                MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + "" + "</td>";
            else
                MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + ((DataTable)Company_DA.Get_Company_By_Id(int.Parse(_CuttingOutStock.Company.ToString()))).Rows[0]["Name"] + "</td>";

            if (dt.Rows[0]["Lot_1"].ToString() == "")
                MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + "" + "</td>";
            else
                MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + ((DataTable)Lot_DA.Get_Lot_By_Id(int.Parse(dt.Rows[0]["Lot_1"].ToString()))).Rows[0]["Name"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Lot" + "</th>";
            if (_CuttingOutStock.Lot_1 == null)
                MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + "" + "</td>";
            else
                MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + ((DataTable)Lot_DA.Get_Lot_By_Id(int.Parse(_CuttingOutStock.Lot_1.ToString()))).Rows[0]["Name"] + "</td>";

            MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + dt.Rows[0]["Pcs"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Pcs" + "</th>";
            MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _CuttingOutStock.Pcs + "</td>";

            MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + dt.Rows[0]["Sqft"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Sqft" + "</th>";
            MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _CuttingOutStock.Sqft + "</td>";

            if (dt.Rows[0]["Lot_2"].ToString() == "")
                MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + "" + "</td>";
            else
                MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + ((DataTable)Lot_DA.Get_Lot_By_Id(int.Parse(dt.Rows[0]["Lot_2"].ToString()))).Rows[0]["Name"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Lot" + "</th>";
            if (_CuttingOutStock.Lot_2 == null)
                MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + "" + "</td>";
            else
                MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + ((DataTable)Lot_DA.Get_Lot_By_Id(int.Parse(_CuttingOutStock.Lot_2.ToString()))).Rows[0]["Name"] + "</td>";

            MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + dt.Rows[0]["Pcs2"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Pcs" + "</th>";
            MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _CuttingOutStock.Pcs2 + "</td>";

            MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + dt.Rows[0]["Sqft2"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Sqft" + "</th>";
            MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _CuttingOutStock.Sqft2 + "</td>";

            MessageDataOld += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + dt.Rows[0]["Description"] + "</td>";
            MessageHeader += "<th align=\"left\" style=\"border: 1px solid #ddd;height: 30px;\">" + "Description" + "</th>";
            MessageDataNew += "<td  style=\"border: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _CuttingOutStock.Description + "</td>";

            #endregion

            MessageDataOld += "</tr>";
            MessageHeader += "</tr>";
            MessageDataNew += "</tr>";

            MessageBody += tableStart + MessageDataOld + MessageHeader + MessageDataNew + tableEnd + "<h3>After Edit</h3>";
            sendMail.sendEmailMessage(ConfigurationManager.AppSettings["From"], ConfigurationManager.AppSettings["To"], ConfigurationManager.AppSettings["Password"], "Cutting OutSource Edit", MessageBody);
        }
        public string Update(int Id, int Company, int Lot1, int Pcs, float Sqft, int Lot2, int Pcs2, float Sqft2, string Description, string Date)
        {
            CuttingOutStock _CuttingOutStock = new CuttingOutStock();

            _CuttingOutStock.Id = Id;
            _CuttingOutStock.Lot_1 = Lot1;
            _CuttingOutStock.Company = Company;
            if (Lot2 != -1)
            {
                _CuttingOutStock.Lot_2 = Lot2;
                _CuttingOutStock.Pcs2 = Pcs2;
                _CuttingOutStock.Sqft2 = Sqft2;
            }
            _CuttingOutStock.Pcs = Pcs;
            _CuttingOutStock.Sqft = Sqft;
            _CuttingOutStock.Date = Convert.ToDateTime(Date);
            _CuttingOutStock.Description = Description;

            #region Cutting
            Cutting _Cutting = new Cutting();

            _Cutting.Lot_1 = Lot1;
            if (Lot2 != -1)
            {
                _Cutting.Lot_2 = Lot2;
                _Cutting.Pcs2 = Pcs2;
                _Cutting.Sqft2 = Sqft2;
            }
            _Cutting.Pcs = Pcs;
            _Cutting.Sqft = Sqft;

            #endregion

            string msg = Validate_Lot(_CuttingOutStock);
            if (msg == "")
            {

                DataTable dt = CuttingOutStock_DA.Get_CuttingOutstock_By_ID(Id);

                msg = validating_Pcs_Sqft_For_Cutter(ref _Cutting, dt.Rows[0]["Lot_1"].ToString(), dt.Rows[0]["Pcs"].ToString(), dt.Rows[0]["Sqft"].ToString(), dt.Rows[0]["Lot_2"].ToString(), dt.Rows[0]["Pcs2"].ToString(), dt.Rows[0]["Sqft2"].ToString());

                msg += CuttingOutStock_DA.UpdateCuttingOutstock(_CuttingOutStock);

                OldPcsSqftEntry(dt.Rows[0]["Lot_1"].ToString(), dt.Rows[0]["Pcs"].ToString(), dt.Rows[0]["Sqft"].ToString());

                if (dt.Rows[0]["Lot_2"].ToString() != "")
                    OldPcsSqftEntry(dt.Rows[0]["Lot_2"].ToString(), dt.Rows[0]["Pcs2"].ToString(), dt.Rows[0]["Sqft2"].ToString());

                UpdateDeliveryForCuttingOutStock(Lot1, Pcs, Sqft, Lot2, Pcs2, Sqft2);

                if (Session["User"].ToString().ToUpper() != ("Mustafa Piracha").ToUpper())
                {
                    SendNotification(_CuttingOutStock, dt);
                }
            }
            return msg;
        }
        public CuttingOutStock Get(int Id)
        {
            CuttingOutStock _CuttingOutStock = new CuttingOutStock();

            DataTable dt = CuttingOutStock_DA.Get_CuttingOutstock_By_ID(Id);

            foreach (DataRow row in dt.Rows)
            {
                _CuttingOutStock.Company = int.Parse(row["Company"].ToString());
                _CuttingOutStock.Lot_1 = int.Parse(row["Lot_1"].ToString());
                _CuttingOutStock.Pcs = int.Parse(row["Pcs"].ToString());
                _CuttingOutStock.Sqft = float.Parse(row["Sqft"].ToString());
                if (row["Lot_2"].ToString() != "")
                    _CuttingOutStock.Lot_2 = int.Parse(row["Lot_2"].ToString());
                if (row["Pcs2"].ToString() != "")
                    _CuttingOutStock.Pcs2 = int.Parse(row["Pcs2"].ToString());
                if (row["Sqft2"].ToString() != "")
                    _CuttingOutStock.Sqft2 = float.Parse(row["Sqft2"].ToString());
                _CuttingOutStock.Date2 = Convert.ToDateTime(row["Date"].ToString()).ToString("MM/dd/yyyy");
                _CuttingOutStock.Description = row["Description"].ToString();

            }
            return _CuttingOutStock;
        }
        private bool Validate_Lot()
        {
            lblMessage.Text = "";
            lblMessage.ForeColor = System.Drawing.Color.Red;
            bool flag = false;

            #region CuttingOutStock

            CuttingOutStock _CuttingOutStock = new CuttingOutStock();

            _CuttingOutStock.Lot_1 = int.Parse(ddlLot1.SelectedValue);

            if (divLot2.Visible == true)
            {
                _CuttingOutStock.Lot_2 = int.Parse(ddlLot2.SelectedValue);
            }
            _CuttingOutStock.Date = Convert.ToDateTime(txtDate.Text);

            #endregion

            // for Lot
            flag = CuttingOutStock_DA.IsLotBeforeOutStock(_CuttingOutStock);

            if (!flag)
            {
                lblMessage.Text = "Your Out Sourcing Date is earlier than Lot";
            }
            return flag;
        }
        protected void InsertCuttingOutStock()
        {
            #region CuttingOutStock
            CuttingOutStock _CuttingOutStock = new CuttingOutStock();

            _CuttingOutStock.Company = int.Parse(ddlCompany.SelectedValue);

            _CuttingOutStock.Lot_1 = int.Parse(ddlLot1.SelectedValue);
            if (ddlLot2.SelectedValue != "")
            {
                _CuttingOutStock.Lot_2 = int.Parse(ddlLot2.SelectedValue);
                _CuttingOutStock.Pcs2 = int.Parse(txtPcs2.Text);
                _CuttingOutStock.Sqft2 = float.Parse(txtSqFt2.Text);
            }
            _CuttingOutStock.Pcs = int.Parse(txtPcs.Text);
            _CuttingOutStock.Sqft = float.Parse(txtSqFt.Text);
            _CuttingOutStock.Date = Convert.ToDateTime(txtDate.Text);
            _CuttingOutStock.Description = txtDescription.Text;

            _CuttingOutStock.IsDeleted = false;
            #endregion

            lblMessage.Text += CuttingOutStock_DA.InsertCuttingOutStock(_CuttingOutStock);
            if (!lblMessage.Text.Contains(Constants.ALREADY_EXIST))
            {
                UpdateDeliveryForCuttingOutStock();
                lblMessage.ForeColor = System.Drawing.Color.Green;

                Response.Write("<script>alert('Inserted Successfully'); document.location='/forms/formCuttingOutStock';</script>");
            }
            else
            {
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }