public void AddComplaints(string sId,string name,string telephone,string email, string cContacted, string emailedSubway, string fRecieved, string pFixed, string comm)
        {
            ComplaintsModel complaintsModel = new ComplaintsModel();

            int storeId = ValidationUtility.ToInteger(sId);

            bool customerContacted = ValidationUtility.ToY_NBool(cContacted);
            bool feedbackRecieved = ValidationUtility.ToY_NBool(fRecieved);
            bool problemFixed = ValidationUtility.ToY_NBool(pFixed);
            bool emailSubway = ValidationUtility.ToY_NBool(emailedSubway);

            ComplaintsDTO complaintsDTO = new ComplaintsDTO();

            complaintsDTO.StoreId = storeId;
            complaintsDTO.ComplaintDate = DateTime.Now;
            complaintsDTO.CustomerContacted = customerContacted;
            complaintsDTO.FeedbackRecieved = feedbackRecieved;
            complaintsDTO.ProblemFixed = problemFixed;
            complaintsDTO.EmailedSubway = emailSubway;
            complaintsDTO.Comment = comm;
            complaintsDTO.Name = name;
            complaintsDTO.TelePhone = telephone;
            complaintsDTO.Email = email;
            complaintsDTO.CreatedDateTime = DateTime.Now;
            complaintsDTO.LastUpdateDateTime = DateTime.Now;

            complaintsModel.AddComplaints(complaintsDTO);
        }
        public void AddComplaints(ComplaintsDTO complaintsDTO)
        {
            DataBaseUtility db = new DataBaseUtility();

            //string query = "INSERT INTO [dbo].[Complaints] ([StoreId],[ComplaintDate],[CustomerContacted],[FeedbackReceived],[ProblemFixed],[Comment],[Response] "
            //               + " ,[CreatedDateTime],[LastUpdateDateTime]) VALUES(" + SQLUtility.getInteger(complaintsDTO.StoreId) + ",'" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.ComplaintDate) + "' ,"
            //              + " '" + complaintsDTO.CustomerContacted + "','" + complaintsDTO.FeedbackRecieved + "','" + complaintsDTO.ProblemFixed + "',"
            //                + " " + SQLUtility.getString(complaintsDTO.Comment) + ", " + SQLUtility.getString(complaintsDTO.Response) + ",'" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.CreatedDateTime) + "','" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.LastUpdateDateTime) + "' )";

            string query = "INSERT INTO [dbo].[Complaints] ([StoreId] ,[ComplaintDate],[CustomerContacted] ,[FeedbackReceived],[ProblemFixed] ,[EmailedSubway] "
                           +" ,[Comment],[Response],[Name] ,[Telephone] ,[Email],[CreatedDateTime] ,[LastUpdateDateTime]) "
                            + " VALUES(" + SQLUtility.getInteger(complaintsDTO.StoreId) + ",'" + SQLUtility.FormateDateYYYYMMDD(complaintsDTO.ComplaintDate) + "', '" + complaintsDTO.CustomerContacted + "','"+complaintsDTO.FeedbackRecieved+"', "
                             + " '" + complaintsDTO.ProblemFixed + "','" + complaintsDTO.EmailedSubway + "'," + SQLUtility.getString(ValidationUtility.TruncateString(complaintsDTO.Comment, 500)) + "," + SQLUtility.getString(ValidationUtility.TruncateString(complaintsDTO.Response, 500)) + "," + SQLUtility.getString(complaintsDTO.Name) + "," + SQLUtility.getString(complaintsDTO.TelePhone) + "," + SQLUtility.getString(complaintsDTO.Email) + ",'" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.CreatedDateTime) + "','" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.LastUpdateDateTime) + "')";
            db.ExecuteUpdate(query);
        }
        public void UpdateComplaintsData(ComplaintsDTO complaintsDTO)
        {
            DataBaseUtility db = new DataBaseUtility();

              //  string query = "update dbo.Complaints set CustomerContacted='" + complaintsDTO.CustomerContacted + "',FeedbackReceived='" + complaintsDTO.FeedbackRecieved + "',ProblemFixed='" + complaintsDTO.ProblemFixed + "',Comment=" + SQLUtility.getString(complaintsDTO.Comment) + ",Response=" + SQLUtility.getString(complaintsDTO.Response) + ",LastUpdateDateTime='" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.LastUpdateDateTime) + "' where Id=" + SQLUtility.getInteger(complaintsDTO.Id) + " ";

            string query = "update dbo.Complaints set CustomerContacted='" + complaintsDTO.CustomerContacted + "',FeedbackReceived='" + complaintsDTO.FeedbackRecieved + "',ProblemFixed='" + complaintsDTO.ProblemFixed + "', "
                              + " EmailedSubway='" + complaintsDTO.EmailedSubway + "' ,Comment=" + SQLUtility.getString(ValidationUtility.TruncateString(complaintsDTO.Comment, 500)) + ",Response=" + SQLUtility.getString(ValidationUtility.TruncateString(complaintsDTO.Response, 500)) + ", "
                            + " Name=" + SQLUtility.getString(complaintsDTO.Name) + ",Telephone=" + SQLUtility.getString(complaintsDTO.TelePhone) + ",Email="+SQLUtility.getString(complaintsDTO.Email)+"  ,LastUpdateDateTime='" + SQLUtility.FormateDateYYYYMMDDWtithTime(complaintsDTO.LastUpdateDateTime) + "' where Id=" + SQLUtility.getInteger(complaintsDTO.Id) + " ";
            db.ExecuteUpdate(query);
        }
        //Get General Manager Complaint
        public ArrayList GetGenManComplaintsList(int sId, DateTime selectDate, int userId)
        {
            var lastDayOfMonth = DateTime.DaysInMonth(selectDate.Year, selectDate.Month);

            DateTime startDateOfMonth = new DateTime(selectDate.Year, selectDate.Month, 1);
            DateTime endDateOfMonth = new DateTime(selectDate.Year, selectDate.Month, lastDayOfMonth);

            ArrayList list = new ArrayList();
            DataBaseUtility db = new DataBaseUtility();
            SqlConnection conn = null;
            conn = db.OpenConnection();
            try
            {
                string query = "";
                if (sId == 0)
                {
                        query = "select c.*,s.StoreNumber from dbo.Complaints c, dbo.Store s  "
                               + " where  c.ComplaintDate >= '" + SQLUtility.FormateDateYYYYMMDD(startDateOfMonth) + "' and c.ComplaintDate <= '" + SQLUtility.FormateDateYYYYMMDD(endDateOfMonth) + "' "
                                 + " and c.StoreId=s.Id and  c.StoreId in (select StoreId from dbo.StoreUser where UserId in(select AreaManagerId from dbo.AssignAreaManagerInfo where GeneralManagerId=" + SQLUtility.getInteger(userId) + " ))   order by Id desc";

                }
                else
                {

                    query = "select c.*,s.StoreNumber "
                                + " from dbo.Complaints c, dbo.Store s  where c.StoreId=s.Id and StoreId=" + SQLUtility.getInteger(sId) + " and ComplaintDate >= '" + SQLUtility.FormateDateYYYYMMDD(startDateOfMonth) + "' and ComplaintDate <= '" + SQLUtility.FormateDateYYYYMMDD(endDateOfMonth) + "'  order by Id desc";

                }

                SqlCommand comm = db.getSQLCommand(query, conn);
                SqlDataReader reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    int id = ValidationUtility.ToInteger(reader["Id"].ToString());
                    int storeId = ValidationUtility.ToInteger(reader["StoreId"].ToString());
                    DateTime complaintDate = ValidationUtility.ToDate(reader["ComplaintDate"].ToString());
                    bool cutomerContacted = ValidationUtility.ToY_NBool(reader["CustomerContacted"].ToString());
                    bool feedbackReceived = ValidationUtility.ToY_NBool(reader["FeedbackReceived"].ToString());
                    bool problemFixed = ValidationUtility.ToY_NBool(reader["ProblemFixed"].ToString());
                    bool emailSubway = ValidationUtility.ToY_NBool(reader["EmailedSubway"].ToString());
                    string comment = reader["Comment"].ToString();
                    string response = reader["Response"].ToString();
                    string name = reader["Name"].ToString();
                    string telephpne = reader["Telephone"].ToString();
                    string email = reader["Email"].ToString();
                    int storeNumber = ValidationUtility.ToInteger(reader["StoreNumber"].ToString());

                    ComplaintsDTO ComplaintsDTO = new ComplaintsDTO { Id = id, StoreId = storeId, ComplaintDate = complaintDate, ComplaintDateToString = complaintDate.ToString("MM/dd/yyyy"), CustomerContacted = cutomerContacted, FeedbackRecieved = feedbackReceived, ProblemFixed = problemFixed, EmailedSubway = emailSubway, Comment = comment, Response = response, Name = name, TelePhone = telephpne, Email = email, StoreNumber = storeNumber };
                    list.Add(ComplaintsDTO);
                }

                reader.Close();

                comm.Dispose();
            }
            catch (Exception ex)
            {
                log.Error("Exception in GetComplaintsList method ", ex);

            }
            finally
            {
                db.CloseConnection(conn);
            }

            return list;
        }
        public void UpdateComplaints(string Id, string name, string telephone, string email, string cContacted, string emailedSubway, string fRecieved, string pFixed, string comm, string resp)
        {
            ComplaintsModel complaintsModel = new ComplaintsModel();

            int id = ValidationUtility.ToInteger(Id);
            bool customerContacted = ValidationUtility.ToY_NBool(cContacted);
            bool feedbackRecieved = ValidationUtility.ToY_NBool(fRecieved);
            bool problemFixed = ValidationUtility.ToY_NBool(pFixed);

            bool emailSubway = ValidationUtility.ToY_NBool(emailedSubway);

            ComplaintsDTO complaintsDTO = new ComplaintsDTO();

            complaintsDTO.Id = id;

            complaintsDTO.CustomerContacted = customerContacted;
            complaintsDTO.FeedbackRecieved = feedbackRecieved;
            complaintsDTO.ProblemFixed = problemFixed;
            complaintsDTO.EmailedSubway = emailSubway;
            complaintsDTO.Comment = comm;
            complaintsDTO.Response = resp;
            complaintsDTO.Name = name;
            complaintsDTO.TelePhone = telephone;
            complaintsDTO.Email = email;

            complaintsDTO.LastUpdateDateTime = DateTime.Now;

            complaintsModel.UpdateComplaintsData(complaintsDTO);
        }