Click here to Skip to main content
15,921,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three different tables:
1)Employee leaves
2)Breakfast order
3)Breakfast Cancel

Employee leave has columns: "Si_no, EmpCode, EmpName, Designation, Leave_Type, LFrom, LTo, Numbersof_leave, Reason, Status, comments"

Breakfast order has: "Emp_ID, Order_For_Date, Order_Day, Order_From, Dish, Price, Quantity, Company_Limit, Extra_Chgs, Total_Cost, Ordered_Date, Emp_Name"

Now,
when user submit leaves (half day(LFrom) / Full day(LFrom) / Casual leave(LFrom and LTo))
His/her breakfast order (Order_For_Date) should get cancelled for the leave applied dates(LFrom to LTo) and the data for the matched dates should get removed from Breakfast Order table and inserted into Breakfast cancel table.

Plz, help me...

What I have tried:

C#
public void deletebreakfast()
{
    DataTable Breakfast = new DataTable();
    var date = DateTime.Now;
    var nextSundayy = date.AddDays(7 - (int)date.DayOfWeek);
    string today = DateTime.Now.ToString("yyyy-MM-dd");
    string nextsunday = nextSundayy.ToString("yyyy-MM-dd");
    cmd = new SqlCommand("select * from tb_Breakfast_data where Order_For_Date between '" + today.Trim() + "' and '" + nextsunday.Trim() + "' and Emp_ID = '" + Session["EmpCode"].ToString() + "'", Connectivity.cn);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(Breakfast);

    if (dd2.SelectedItem.Text == "Half Day Leave" || dd2.SelectedItem.Text == "Full Day Leave")
    {
        foreach (DataRow dr in Breakfast.Rows)
    {
            if()
        try
        {
            string Fdate = "", Todate = "", Empcode = "";
            
            try
            {
                Fdate = dr["LFrom"].ToString();
            }
            catch { }
            try
            {
                Todate = dr["LTo"].ToString();
            }
            catch { }
            try
            {
                Empcode = dr["EmpCode"].ToString();
            
            }
           catch { }
            
            string Query1 = "";
            string Query2 = "";

            if (Todate.Trim() == "")
            {
        
Query1 = "select * from tb_Breakfast_data where Order_For_Date  = '" + Fdate.Trim() + "' and Emp_ID='" + Empcode.Trim() + "'";
                Query2 =  "
            }
                
            else
                 
{
   
    DateTime startDate ;
    DateTime endDate ;
    string date1 = "";
 {
    for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1.0))
        {
        date1 = Convert.ToString(date);
        allDateb.Add(date1);
    }
    
    return allDateb;
Posted
Updated 2-Jun-17 2:15am
v4
Comments
Richard MacCutchan 30-May-17 3:19am    
Why are you storing dates and employee id as text rather than natural values? That just makes it difficult to find the data you are interested in.
Maciej Los 30-May-17 3:20am    
Do not convert dates to string! You have to work on dates.
ZurdoDev 30-May-17 8:50am    
What is not working? Where are you stuck?
Member 13201220 31-May-17 0:35am    
have logic but not able to implement it.
(for current date to next seven days)
case 1:(for Half-day / Full-day leave) first get the Order_for_date column data from Breakfast table then get LFrom dates from Employee leave table=> Compare both if matched move matched dates data to new table Breakfast cancel.
Case 2 (Casual Leave): get Order_for_date column data from Breakfast table then get LFrom to LTo columns data =>Compare both also consider the dates between 'LFrom to LTo' if matched move to Breakfast cancel table. (EmpCode=Emp_ID). (Breakfast should get cancelled for all the dates for which the employee applied for leaves)

Not able to implement.
suggest if any other way to get this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900