Exemplo n.º 1
0
        protected void OnUpdateNialDateClick(object sender, EventArgs e)
        {
            NailDate date = Session["selectedNailDate"] as NailDate;

            Logger.Instance.LogInfo("Update nail date " + date);
            date.ClientName  = nailDatePanel.ClientName;
            date.ClientPhone = nailDatePanel.Phone;
            date.StartTime   = nailDatePanel.StartTime;
            short tmpTips = 0;

            if (short.TryParse(tipsField.Text, out tmpTips))
            {
                date.Tips = tmpTips;
            }
            else
            {
                date.Tips = null;
            }
            var oldServices = (Session["selectedServices"] as List <int>);

            HandleNailDateInSessionAndRefresh(nd =>
            {
                DataBaseHandler.Instance.UpdateNailDate(nd, nailDatePanel.SelectedServicesIDs, oldServices);
                Logger.Instance.LogInfo("Nail date updated to " + date);
            });

            Session.Clear();
        }
Exemplo n.º 2
0
 protected void scheduler_SelectionChanged(List <NailDate> obj)
 {
     buttonsPanel.Visible = true;
     foreach (string time in Settings.Instance.AvailableTimes)
     {
         TimeSpan span = TimeSpan.Parse(time);
         NailDate date = null;
         Button   b    = new Button();
         if ((date = obj.FirstOrDefault(a => a.StartTime.TimeOfDay == span)) != null)
         {
             b.Text              = "Занято/Изменить";
             b.CssClass          = "reserved";
             b.OnClientClick     = "showEnterPhonePrompt(this.getAttribute('dateid'))";
             b.UseSubmitBehavior = false;
             b.Attributes.Add("dateid", date.ID.ToString());
         }
         else
         {
             DateTime targetTime = scheduler.SelectedDate.Add(span);
             if (targetTime < DateTime.Now)
             {
                 continue;
             }
             b.Text              = "Записаться на " + time;
             b.CssClass          = "notreserved";
             b.OnClientClick     = string.Format("addNewNailDate('{0}')", (targetTime - DateTime.MinValue).TotalMinutes); //We subtract the minimum value to obtain the type of a variable that has Timspan TotalMinutes field
             b.UseSubmitBehavior = false;
         }
         buttonsPanel.Controls.Add(b);
     }
 }
Exemplo n.º 3
0
        private Control GenerateContentForUserCell(NailDate existsNailDate, DateTime certainTime)
        {
            Control result = null;

            if (certainTime <= nowDateTime)
            {
                return(null);
            }
            if (existsNailDate == null)
            {
                var b = new TagButton()
                {
                    Tag = certainTime, Text = "Записаться"
                };
                //b.Attributes.Add("time", certainTime.ToString("Дата dd MMMM yyyy HH:mm"));
                //b.UseSubmitBehavior = false;
                //b.OnClientClick = "showModal(event); return false;";
                b.Click += onAddDateButtonClick;
                result   = b;
            }
            else
            {
                result = new Label()
                {
                    Text = "Занято"
                };
                (result as Label).Attributes.Add("onclick", "showEnterPhonePrompt(this.getAttribute('dateid'))");
                (result as Label).Attributes.Add("onmouseover", "this.innerHTML = 'Изменить'");
                (result as Label).Attributes.Add("onmouseleave", "this.innerHTML = 'Занято'");
                (result as Label).Attributes.Add("dateid", existsNailDate.ID.ToString());
            }
            return(result);
        }
Exemplo n.º 4
0
        public NailDate GetNailDateById(int nailDateId)
        {
            string   query = "select * from NailDates where Id >= @id";
            NailDate dates = null;

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = nailDateId;
                    cn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    try
                    {
                        dr.Read();
                        dates = NailDate.Parse(dr);
                    }
                    catch (System.Exception ex)
                    {
                        LastErrorMessage = ex.Message;
                    }
                    finally
                    {
                        cn.Close();
                    }
                }
            return(dates);
        }
Exemplo n.º 5
0
        public bool UpdateNailDate(NailDate date, List <int> currentSelServicesIDs, List <int> oldServicesIDs)
        {
            string query             = "update dbo.NailDates set StartTime = @StartTime, Duration = @Duration, ClientName = @ClientName, ClientPhone = @ClientPhone, tips = @tips where id=@ID;";
            var    servWithOutDesign = currentSelServicesIDs.Where(w => w != 10);

            if (servWithOutDesign.Count() == 0)
            {
                query += "delete from dbo.NailDateService where nailDateId = @ID;";
            }
            else
            {
                query += "delete from dbo.NailDateService where nailDateId = @ID and serviceId not in (" + String.Join(",", servWithOutDesign) + ");";
            }

            var tmp = oldServicesIDs.Where(w => w != 10);

            foreach (int id in tmp)
            {
                currentSelServicesIDs.Remove(id);
            }
            currentSelServicesIDs.ForEach(fe => query += String.Format("insert into dbo.NailDateService (nailDateId, serviceId) values (@ID, @serviceId{0});", fe));

            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value                  = date.ID;
                    cmd.Parameters.Add("@StartTime", SqlDbType.DateTime).Value      = date.StartTime;
                    cmd.Parameters.Add("@Duration", SqlDbType.BigInt).Value         = date.Duration.TotalMinutes;
                    cmd.Parameters.Add("@ClientName", SqlDbType.NText, 20).Value    = date.ClientName;
                    cmd.Parameters.Add("@ClientPhone", SqlDbType.VarChar, 15).Value = date.ClientPhone;

                    if (date.Tips.HasValue)
                    {
                        cmd.Parameters.Add("@tips", SqlDbType.SmallInt).Value = date.Tips;
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@tips", DBNull.Value);
                    }

                    currentSelServicesIDs.Distinct().ToList().ForEach(i => cmd.Parameters.Add(String.Format("@serviceId{0}", i), SqlDbType.Int).Value = i);
                    cn.Open();
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch
                    {
                        return(false);
                    }
                    finally
                    {
                        cn.Close();
                    }
                    return(true);
                }
        }
Exemplo n.º 6
0
        private void OnDeleteNailDateClick(SelectServicesSheet obj)
        {
            NailDate date = Session["nailDateForEdit"] as NailDate;

            DataBaseHandler.Instance.DropNailDate(date);
            ShowAlertBox("Вы отменили запись, пожалуйста возвращайтесь к нам:)");
            MailSender.SendDeletedMailNotification(date);
            Session.Clear();
        }
Exemplo n.º 7
0
        private void HandleNailDateInSessionAndRefresh(Action <NailDate> handler)
        {
            NailDate date = Session["selectedNailDate"] as NailDate;

            Session["selectedNailDate"] = null;
            if (date == null)
            {
                return;
            }
            handler(date);
            Session.Clear();
            Response.Redirect(Request.RawUrl);
        }
Exemplo n.º 8
0
        public static NailDate Parse(SqlDataReader reader)
        {
            var result = new NailDate();

            result.ID        = (int)reader["id"];
            result.StartTime = (DateTime)reader["StartTime"];
#warning fix this dummy when need real duration of nail date
            result.Duration    = (result.StartTime.Hour != 13) ? TimeSpan.FromHours(3): TimeSpan.FromHours(4);          //TimeSpan.FromTicks((Int64)reader["Duration"]);
            result.ClientName  = reader["ClientName"] as string;
            result.ClientPhone = reader["ClientPhone"] as string;
            result.Tips        = reader["tips"] != System.DBNull.Value ? (short)reader["tips"] : (short?)null;
            return(result);
        }
Exemplo n.º 9
0
        protected void SaveUsedMaterialsForDate(object sender, EventArgs e)
        {
            List <int> usedMatIds = new List <int>();

            foreach (GridViewRow row in usedMaterialsTable.Rows)
            {
                CheckBox check = row.FindControl("CheckBox1") as CheckBox;
                if (check != null && check.Checked)
                {
                    usedMatIds.Add(int.Parse(row.Cells[0].Text));
                }
            }
            NailDate date = Session["selectedNailDate"] as NailDate;

            DataBaseHandler.Instance.SaveUsedMaterialsForNailDate(date.ID, usedMatIds);
        }
Exemplo n.º 10
0
        public void DropNailDate(NailDate date)
        {
            string query = "delete from dbo.NailDates where Id = @ID;";

            query += "delete from dbo.NailDateService where nailDateId = @ID;";

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    // define parameters and their values
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value = date.ID;
                    cn.Open();
                    cmd.ExecuteNonQuery();
                    cn.Close();
                }
        }
Exemplo n.º 11
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //sheet.DataBind();
     if (Session["nailDateForEdit"] != null && IsPostBack == false)
     {
         services.SetDisplayEditDeleteButtons(true);
         NailDate date = Session["nailDateForEdit"] as NailDate;
         services.StartTime  = date.StartTime;
         services.ClientName = date.ClientName;
         services.Phone      = date.ClientPhone;
         var ids = DataBaseHandler.Instance.GetServicesIDsForDate(date.ID);
         services.SelectedServicesIDs   = ids;
         Session["oldSelectedServices"] = ids;
     }
     services.UpdateNailDate += OnUpdateNailDateClick;
     services.DeleteNailDate += OnDeleteNailDateClick;
 }
Exemplo n.º 12
0
        private void OnNailDateSeleted(NailDate obj)
        {
            dateCalendar.TodaysDate   = obj.StartTime;
            dateCalendar.SelectedDate = dateCalendar.TodaysDate;
            DateSelectionChanged(dateCalendar, null);
            nailDatePanel.StartTime  = obj.StartTime;
            nailDatePanel.ClientName = obj.ClientName;
            nailDatePanel.Phone      = obj.ClientPhone;
            tipsField.Text           = obj.Tips.ToString();

            var selectedServices = DataBaseHandler.Instance.GetServicesIDsForDate(obj.ID);

            Session["nailDateIsSelected"]     = true;
            Session["selectedServices"]       = selectedServices;
            Session["selectedNailDate"]       = obj;
            Session["selectedNailDateID"]     = obj.ID;
            nailDatePanel.SelectedServicesIDs = selectedServices;
            detailDataTable.Visible           = true;
        }
Exemplo n.º 13
0
        private void OnUpdateNailDateClick(SelectServicesSheet obj)
        {
            NailDate date = Session["nailDateForEdit"] as NailDate;

            date.ClientName  = services.ClientName;
            date.ClientPhone = services.Phone;
            var  oldServices = (Session["oldSelectedServices"] as List <int>);
            bool result      = DataBaseHandler.Instance.UpdateNailDate(date, services.SelectedServicesIDs, oldServices);

            Session.Clear();
            if (result)
            {
                ShowAlertBox("Ваша запись успешно обновлена");
            }
            else
            {
                ShowAlertBox("Не удалось обновить запись. Пожалйста свяжитесь с нами по тел: +380939372858 или +380953464708");
            }
            MailSender.SendUpdatedMailNotification(date);
        }
Exemplo n.º 14
0
        private List <NailDate> GetNailDatesSinceDate(DateTime sinceTime)
        {
            string query = "select * from NailDates where StartTime >= @DateFrom";
            var    dates = new List <NailDate>();

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@DateFrom", SqlDbType.DateTime).Value = sinceTime;
                    cn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        dates.Add(NailDate.Parse(dr));
                    }
                    cn.Close();
                }
            return(dates);
        }
Exemplo n.º 15
0
        private Control GenerateContentForOwnerCell(NailDate existsNailDate, DateTime certainTime)
        {
            var b = new TagButton()
            {
                Tag = existsNailDate
            };

            b.Click += onButtonPressedByOwner;
            if (existsNailDate != null)
            {
                b.Text = existsNailDate.ClientName;
                //b.BackColor = Color.FromArgb(1, 228, 83, 131);
            }
            else
            {
                b.Tag  = certainTime;
                b.Text = certainTime > nowDateTime ? "Блокировать" : "Добавить";
            }
            return(b);
        }
Exemplo n.º 16
0
        public List <NailDate> GetNailDatesForTimeRange(DateTime sinceTime, DateTime tillTime)
        {
            string query = "select * from NailDates where StartTime >= @sinceTime and StartTime <=@tillTime order by StartTime";
            var    dates = new List <NailDate>();

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@sinceTime", SqlDbType.DateTime).Value = sinceTime;
                    cmd.Parameters.Add("@tillTime", SqlDbType.DateTime).Value  = tillTime.AddDays(1);
                    cn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        dates.Add(NailDate.Parse(dr));
                    }
                    cn.Close();
                }
            return(dates);
        }
Exemplo n.º 17
0
        public static void SendUpdatedMailNotification(NailDate updatedNailDate)
        {
            MailMessage mailMsg = new MailMessage();

            mailMsg.From = new MailAddress("*****@*****.**");
#if DEBUG
            mailMsg.To.Add(new MailAddress("*****@*****.**"));
#else
            mailMsg.To.Add(new MailAddress("*****@*****.**"));
#endif
            mailMsg.IsBodyHtml = false;
            mailMsg.Subject    = "Запись на" + updatedNailDate.StartTime + "изменена";
            string     body   = updatedNailDate.ToString();
            SmtpClient client = new SmtpClient("smtp.mail.ru", 25);
            client.Credentials = new System.Net.NetworkCredential()
            {
                UserName = "******", Password = "******"
            };
            client.EnableSsl = true;

            client.Send(mailMsg);
        }
Exemplo n.º 18
0
        public void drawWeek(DateTime highlightedDate)
        {
            int odd = 0;

            foreach (string time in Settings.Instance.AvailableTimes)
            {
                DateTime currentDay = FirstDay;
                var      row        = new TableRow();
                var      nailTime   = TimeSpan.Parse(time);
                var      timeCell   = new TableCell();
                timeCell.Text     = time;
                timeCell.CssClass = "timeCell";
                row.Cells.Add(timeCell);

                odd++;
                for (int i = 1; i < 8; i++)
                {
                    var dateCell = new TableCell();                    // { Width = 100, Height = 30 };

                    var      certainTime    = currentDay.Date.Add(nailTime);
                    NailDate existsNailDate = WeekDates.FirstOrDefault(a => a.StartTime == certainTime);
                    if (existsNailDate != null && (existsNailDate.StartTime > nowDateTime || _currentMode == Mode.Owner))
                    {
                        dateCell.CssClass = "reserved";                        //backColor = StyleColors.Reserved;
                    }
                    else
                    if (currentDay.Date == nowDateTime.Date)
                    {
                        dateCell.CssClass = "active";                        //backColor = StyleColors.LightActive;
                    }
                    else
                    {
                        dateCell.CssClass = odd % 2 == 0 ? "evenCell" : "notEvenCell";                        //backColor = odd % 2 == 0 ? StyleColors.EvenLines : StyleColors.NotEvenLines;
                    }
                    Control innerControl = null;

                    switch (_currentMode)
                    {
                    case Mode.User:
                        innerControl = GenerateContentForUserCell(existsNailDate, certainTime);
                        break;

                    case Mode.Owner:
                        innerControl = GenerateContentForOwnerCell(existsNailDate, certainTime);
                        break;
                    }

                    if (highlightedDate == certainTime && innerControl is Label)
                    {
                        (innerControl as Label).Text = "Ваша запись";
                        dateCell.CssClass            = "alterActive";
                    }

                    if (innerControl != null)
                    {
                        dateCell.Controls.Add(innerControl);
                    }
                    row.Cells.Add(dateCell);
                    currentDay = currentDay.AddDays(1);
                }
                Rows.Add(row);
            }
        }
Exemplo n.º 19
0
 private void OnNailDateSelected(NailDate date)
 {
     NailDateSelected?.Invoke(date);
 }