private void AddPayment_Load(object sender, EventArgs e)
 {
     PersianDateFormatter pdf = new PersianDateFormatter();
     bSave.DialogResult = DialogResult.OK;
     bCancel.DialogResult = DialogResult.Cancel;
     tPaymentDate.Text = pdf.getDateString(DateTime.Now);
 }
 private void bSave_Click(object sender, EventArgs e)
 {
     ContractRepository crep = new ContractRepository();
     Contract contract = crep.getContract(contractId);
     PaymentRepository repository = new PaymentRepository();
     PersianDateFormatter pdf = new PersianDateFormatter();
     Payment payment = new Payment();
     payment.ContractId = contractId;
     payment.AmountOfPayment = Convert.ToInt32(tPayment.Text);
     payment.DateOfPayment = pdf.convert(tPaymentDate.Text);
     DateModel dm = pdf.getSplittedDateIntegers(payment.DateOfPayment.Value);
     payment.Year = dm.Year;
     payment.Month = dm.Month;
     payment.Day = dm.Day;
     contract.Payment += payment.AmountOfPayment;
     repository.addPayment(payment);
     crep.updateContract(contract);
 }
 private void AddAppointment_Load(object sender, EventArgs e)
 {
     DefaultSettingsRepository repo = new DefaultSettingsRepository();
     radCheckedDropDownList1.DataSource = repo.GetSetingsByType("price").ToList();
     radCheckedDropDownList1.DisplayMember = "Name";
     radCheckedDropDownList1.ValueMember = "Value";
     bSave.DialogResult = DialogResult.OK;
     bCancel.DialogResult = DialogResult.Cancel;
     PersianDateFormatter pdf = new PersianDateFormatter();
     tTime.Format = DateTimePickerFormat.Custom;
     tTime.CustomFormat = "HH:mm";
     tTime.ShowUpDown = true;
     tDate.Text = pdf.getDateString(DateTime.Now);
 }
        private void bSave_Click(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            AppointmentRepository appRepo = new AppointmentRepository();
            ContractRepository cRepo = new ContractRepository();
            Contract contract = cRepo.getContract(contractId);

            Appointment app = new Appointment();
            string description = "";
            int value = 0;
            foreach (var item in radCheckedDropDownList1.CheckedItems)
            {
                description += item.DisplayValue.ToString() + "/";
                value += Convert.ToInt32(item.Value);
            }
            contract.ContractPayment += value;
            cRepo.updateContract(contract);
            app.ContractId = contractId;
            description = description.Remove(description.Length - 1);
            app.Description = description;

            app.AppointmentDate = pdf.convert(tDate.Text);
            TimeSpan ts = new TimeSpan(tTime.Value.TimeOfDay.Hours, tTime.Value.TimeOfDay.Minutes, 0);
            app.AppointmentTime = ts;
            appRepo.addAppointment(app);
        }
 private void toolStripbNext_Click(object sender, EventArgs e)
 {
     PersianDateFormatter pdf = new PersianDateFormatter();
     DateTime dt = DateTime.Now;
     dayCounter++;
     dt = dt.AddDays(dayCounter);
     toolStripTextBox1.Text = pdf.getDateString(dt);
     OtherRepository otherRepository = new OtherRepository();
     radGridView1.DataSource = otherRepository.getCustomerJoinContract(dt);
 }
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     PersianDateFormatter pdf = new PersianDateFormatter();
     int date = pdf.convert(toolStripTextBox1.Text);
     OtherRepository otherRepository = new OtherRepository();
     radGridView1.DataSource = otherRepository.getCustomerJoinContract(date);
 }
        private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            //TimeSpan eight = new TimeSpan(8,0,0);
            TimeSpan ten = new TimeSpan(10, 0, 0);
            TimeSpan twelve = new TimeSpan(12, 0, 0);
            TimeSpan fourteen = new TimeSpan(14, 0, 0);
            TimeSpan sixteen = new TimeSpan(16, 0, 0);
            TimeSpan eighteen = new TimeSpan(18, 0, 0);
            TimeSpan twenty = new TimeSpan(20, 0, 0);

            PersianDateFormatter pdf = new PersianDateFormatter();
            DateTime dt = DateTime.Now;
            TimeSpan ts = new TimeSpan(dt.TimeOfDay.Hours, dt.TimeOfDay.Minutes, 0);
            int gridDate = Convert.ToInt32(e.RowElement.RowInfo.Cells[5].Value.ToString());
            int currentDate = pdf.getDateInteger(dt);
            TimeSpan gridTimeSpan = (TimeSpan)e.RowElement.RowInfo.Cells[4].Value;
            if (e.RowElement.RowInfo.Index > -1)
            {
                if (TimeSpan.Compare(gridTimeSpan, ts) < 0 && gridDate <= currentDate || gridDate < currentDate)
                {

                    e.RowElement.BackColor = Color.FromArgb(245, 245, 245);
                }
                else
                {
                    if (TimeSpan.Compare(gridTimeSpan, ten) < 0)
                    {
                        //8 10
                        e.RowElement.BackColor = Color.FromArgb(255, 252, 220);
                    }
                    else if (TimeSpan.Compare(gridTimeSpan, twelve) < 0)
                    {
                        //10 12
                        e.RowElement.BackColor = Color.FromArgb(255, 247, 179);
                    }
                    else if (TimeSpan.Compare(gridTimeSpan, fourteen) < 0)
                    {
                        //12 14
                        e.RowElement.BackColor = Color.FromArgb(255, 232, 138);
                    }
                    else if (TimeSpan.Compare(gridTimeSpan, sixteen) < 0)
                    {
                        //14 16
                        e.RowElement.BackColor = Color.FromArgb(255, 193, 74);

                    }
                    else if (TimeSpan.Compare(gridTimeSpan, eighteen) < 0)
                    {
                        //16 18
                        e.RowElement.BackColor = Color.FromArgb(255, 189, 234);
                    }
                    else if (TimeSpan.Compare(gridTimeSpan, twenty) < 0)
                    {
                        //18 20
                        e.RowElement.BackColor = Color.FromArgb(227, 166, 255);
                    }
                    else
                    {
                        e.RowElement.BackColor = Color.FromArgb(196, 180, 255);
                    }
                }

            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            int date = pdf.convert(toolStripTextBox1.Text);
            OtherRepository otherRepository = new OtherRepository();
            radGridView1.DataSource = otherRepository.getCustomerJoinContract(date);

            /////////////////////////////////////////////////
            DefaultSettingsRepository dRepo = new DefaultSettingsRepository();
            DefaultSetting gsmPort = dRepo.GetSetting("gsm_port");
            DefaultSetting lastSend = dRepo.GetSetting("last_send");

            if (lastSend == null)
            {
                DefaultSetting ls = new DefaultSetting();
                ls.Value = "13000101";
                ls.Name = "last_send";
                dRepo.AddSettings(ls);
            }
            else
            {
                int lastSendInt = Convert.ToInt32(lastSend.Value);
                int todayInt = pdf.getDateInteger(DateTime.Now);
                int x = 0;
                if (todayInt <= lastSendInt)
                {
                    return;
                }
            }

            if (gsmPort != null)
            {

                if (gsmPort.Value != "NULL")
                {
                    try
                    {
                        GsmCommMain comm = new GsmCommMain(gsmPort.Value, 9600, 150);
                        comm.Open();
                        byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha16Bit;

                        DefaultSetting sendTime = dRepo.GetSetting("send_message_time");
                        DefaultSetting days = dRepo.GetSetting("days_before_send");
                        DefaultSetting text = dRepo.GetSetting("message_text");
                        int daysInteger = Convert.ToInt32(days.Value);

                        TimeSpan ts = TimeSpan.Parse(sendTime.Value);
                        TimeSpan nts = DateTime.Now.TimeOfDay;
                        TimeSpan fivemin = TimeSpan.FromMinutes(5);

                        if (nts.CompareTo(ts) >= 0)
                        {
                            if (nts.Subtract(ts).CompareTo(fivemin) > 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (ts.Subtract(nts).CompareTo(fivemin) > 0)
                            {
                                return;
                            }
                        }

                        DateTime dt = DateTime.Now;
                        dt = dt.AddDays(daysInteger);
                        string dateString = pdf.getDateString(dt);

                        object customers = otherRepository.getCustomerJoinContract(dt);

                        IEnumerable<object> collection = (IEnumerable<object>)customers;
                        foreach (object item in collection)
                        {
                            var nameOfProperty = "PhoneNumber";
                            var propertyInfo = item.GetType().GetProperty(nameOfProperty);
                            var phoneNumber = propertyInfo.GetValue(item, null);

                            var nameOfProperty2 = "Time";
                            var propertyInfo2 = item.GetType().GetProperty(nameOfProperty2);
                            var time = propertyInfo2.GetValue(item, null);

                            string timeString = time.ToString();
                            timeString = timeString.Remove(timeString.Length-3);

                            string smsText = text.Value + Environment.NewLine + dateString + Environment.NewLine + timeString;

                            SmsSubmitPdu pdu = new SmsSubmitPdu(smsText, phoneNumber.ToString(), dcs);
                            comm.SendMessage(pdu);
                        }

                        DefaultSettingsRepository dRepo2 = new DefaultSettingsRepository();
                        DefaultSetting lsls =  dRepo2.GetSetting("last_send");
                        lsls.Value = pdf.getDateInteger(DateTime.Now).ToString();
                        dRepo2.UpdateSetting(lsls);

                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
        private void CustomerInfoForm_Load(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            CustomerRepository repository = new CustomerRepository();
            Customer customer = repository.getCustomer(customerId);
            lName.Text = customer.FirstName + " " + customer.LastName;
            lPhoneNumber.Text = "شماره تماس:" + "   " + customer.PhoneNumber;
            lCreatedDate.Text = "تاریخ ایجاد:" + "   " + pdf.convert(customer.CreatedDate.Value);
            if (String.IsNullOrWhiteSpace(customer.Description))
            {
                lDescription.Text = "توضیحات:" + "   " + "-";
            }
            else
            {
                lDescription.Text = "توضیحات:" + "   " + customer.Description;
            }
            ContractRepository crepository = new ContractRepository();
            radGridView1.DataSource = crepository.getContractsByCustomerId(customerId).ToList();

            ((GridTableElement)radGridView1.TableElement).AlternatingRowColor = Color.FromArgb(215, 234, 124);
            radGridView1.TableElement.RowHeight = 25;
            ((GridTableElement)radGridView2.TableElement).AlternatingRowColor = Color.FromArgb(255, 205, 139);
            radGridView2.TableElement.RowHeight = 25;
            ((GridTableElement)radGridView3.TableElement).AlternatingRowColor = Color.FromArgb(240, 240, 240);
            radGridView3.TableElement.RowHeight = 25;

            if (radGridView1.SelectedRows.Count > 0)
            {
                //MessageBox.Show(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
                PaymentRepository paymentRepository = new PaymentRepository();
                AppointmentRepository appointmentRepository = new AppointmentRepository();
                selectedContractId = Convert.ToInt32(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
                radGridView2.DataSource = paymentRepository.getPaymentsByContractId(selectedContractId).ToList();
                radGridView3.DataSource = appointmentRepository.getAppointmentByContractId(selectedContractId).ToList();
            }

            if (radGridView1.SelectedRows.Count < 1)
            {
                bNewAppointment.Enabled = false;
                bNewPayment.Enabled = false;
            }
        }
        private void EasyAccounting_Load(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            toolStripTextBox1.Text = pdf.getDateString(DateTime.Now);
            ((GridTableElement)radGridView1.TableElement).AlternatingRowColor = Color.FromArgb(215, 234, 124);
            radGridView1.TableElement.RowHeight = 50;
            OtherRepository otherRepository = new OtherRepository();
            radGridView1.DataSource = otherRepository.getCustomerJoinContract(DateTime.Now);
            timer1.Start();

            //GsmCommMain comm = new GsmCommMain("COM8", 9600, 150);
            //comm.Open();
            //byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha16Bit;
            //SmsSubmitPdu pdu = new SmsSubmitPdu("امین", "09398987855", dcs);
            //comm.SendMessage(pdu);
        }
        private void bEditInfo_Click(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            CustomerRepository repository = new CustomerRepository();
            Customer customer = repository.getCustomer(customerId);
            EditCustomerForm editCustomerForm = new EditCustomerForm(customer);
            var result = editCustomerForm.ShowDialog();
            if (result == DialogResult.OK)
            {
                CustomerRepository cr = new CustomerRepository();
                customer = cr.getCustomer(customerId);
                lName.Text = customer.FirstName + " " + customer.LastName;
                lPhoneNumber.Text = "شماره تماس:" + "   " + customer.PhoneNumber;
                lCreatedDate.Text = "تاریخ ایجاد:" + "   " + pdf.convert(customer.CreatedDate.Value);
                if (String.IsNullOrWhiteSpace(customer.Description))
                {
                    lDescription.Text = "توضیحات:" + "   " + "-";
                }
                else
                {
                    lDescription.Text = "توضیحات:" + "   " + customer.Description;
                }

            }
        }
        private void bSave_Click(object sender, EventArgs e)
        {
            if (isNewContract)
            {
                PersianDateFormatter pdf = new PersianDateFormatter();
                ContractRepository repository = new ContractRepository();
                Contract contract = new Contract();
                contract.ContractPayment = Convert.ToInt32(tPayment.Text);
                contract.ContractStartDate = pdf.convert(tStartDate.Text);
                contract.CustomerId = this.customerId;
                contract.Description = tDescription.Text;
                contract.IsAppointmentFinished = cIsFinished.Checked;
                if (cIsFinished.Checked)
                {
                    contract.ContractEndDate = pdf.getDateInteger(DateTime.Now);
                }
                if (!String.IsNullOrWhiteSpace(tNextAppointmentDate.Text))
                {
                    contract.NextAppointmentDate = pdf.convert(tNextAppointmentDate.Text);
                }
                if (!String.IsNullOrWhiteSpace(tNextAppointmentTime.Text))
                {
                    TimeSpan ts = new TimeSpan(tNextAppointmentTime.Value.TimeOfDay.Hours, tNextAppointmentTime.Value.TimeOfDay.Minutes, 0);
                    contract.NextAppointmentTime = ts;
                }
                contract.Payment = 0;
                repository.addContract(contract);

            }
            else
            {
                PersianDateFormatter pdf = new PersianDateFormatter();
                ContractRepository repository = new ContractRepository();
                Contract contract = repository.getContract(contractId);
                contract.Id = contractId;
                contract.CustomerId = customerId;
                contract.ContractPayment = Convert.ToInt32(tPayment.Text);
                contract.ContractStartDate = pdf.convert(tStartDate.Text);
                contract.Description = tDescription.Text;
                contract.IsAppointmentFinished = cIsFinished.Checked;
                if (cIsFinished.Checked)
                {
                    contract.ContractEndDate = pdf.getDateInteger(DateTime.Now);
                }
                if (!String.IsNullOrWhiteSpace(tNextAppointmentDate.Text))
                {
                    contract.NextAppointmentDate = pdf.convert(tNextAppointmentDate.Text);
                }
                if (!String.IsNullOrWhiteSpace(tNextAppointmentTime.Text))
                {
                    TimeSpan ts = new TimeSpan(tNextAppointmentTime.Value.TimeOfDay.Hours, tNextAppointmentTime.Value.TimeOfDay.Minutes, 0);
                    contract.NextAppointmentTime = ts;
                }
                repository.updateContract(contract);
            }
        }
        private void AddEditContractForm_Load(object sender, EventArgs e)
        {
            bSave.DialogResult = DialogResult.OK;
            bCancel.DialogResult = DialogResult.Cancel;
            PersianDateFormatter pdf = new PersianDateFormatter();
            tNextAppointmentTime.Format = DateTimePickerFormat.Custom;
            tNextAppointmentTime.CustomFormat = "HH:mm";
            tNextAppointmentTime.ShowUpDown = true;
            if (isNewContract)
            {
                tPayment.Text = "0";
                tStartDate.Text = pdf.getDateString(DateTime.Now);
                tNextAppointmentDate.Text = pdf.getDateString(DateTime.Now.AddMonths(1));

            }
            else
            {
                ContractRepository repository = new ContractRepository();
                Contract contract = repository.getContract(contractId);
                tPayment.Text = contract.ContractPayment.Value.ToString();

                tNextAppointmentDate.Text = pdf.convert(contract.NextAppointmentDate.Value);
                tStartDate.Text = pdf.convert(contract.ContractStartDate.Value);

                if (contract.NextAppointmentTime.Value != null)
                {
                    DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0).Add(contract.NextAppointmentTime.Value);

                    tNextAppointmentTime.Value = dt;
                }
                if (!String.IsNullOrWhiteSpace(contract.Description))
                {
                    tDescription.Text = contract.Description;
                }
                if (contract.IsAppointmentFinished.Value == true)
                {
                    cIsFinished.Checked = true;
                }
            }
        }
        private void EditAppointmentForm_Load(object sender, EventArgs e)
        {
            DefaultSettingsRepository dRepo = new DefaultSettingsRepository();
            radCheckedDropDownList1.DataSource = dRepo.GetSetingsByType("price").ToList();
            radCheckedDropDownList1.DisplayMember = "Name";
            radCheckedDropDownList1.ValueMember = "Value";

            PersianDateFormatter pdf = new PersianDateFormatter();
            tTime.Format = DateTimePickerFormat.Custom;
            tTime.CustomFormat = "HH:mm";
            tTime.ShowUpDown = true;
            bSave.DialogResult = DialogResult.OK;
            bCancel.DialogResult = DialogResult.Cancel;
            AppointmentRepository repo = new AppointmentRepository();
            Appointment appo = repo.getAppointment(appointmentId);
            DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0).Add(appo.AppointmentTime.Value);
            tTime.Value = dt;
            tDate.Text = pdf.convert(appo.AppointmentDate.Value);
            string[] parts = appo.Description.Split('/');

            foreach (RadCheckedListDataItem item in radCheckedDropDownList1.Items)
            {
                if (parts.Contains(item.DisplayValue.ToString()))
                {
                    item.Checked = true;
                    unchangedValue += Convert.ToInt32(item.Value.ToString());
                }
            }
        }
        private void bSave_Click(object sender, EventArgs e)
        {
            Customer customer = new Customer();
            CustomerRepository repository = new CustomerRepository();
            if (String.IsNullOrWhiteSpace(tName.Text) || String.IsNullOrWhiteSpace(tLastName.Text) || String.IsNullOrWhiteSpace(tPhoneNumber.Text))
            {
                MessageBox.Show("اطلاعات کامل وارد نشده است");
                return;
            }
            PersianDateFormatter pdf = new PersianDateFormatter();
            customer.CreatedDate = pdf.getDateInteger(DateTime.Now);
            customer.FirstName = tName.Text;
            customer.LastName = tLastName.Text;
            customer.PhoneNumber = tPhoneNumber.Text;
            if (rWoman.Checked)
            {
                customer.Gender = true;
            }
            else
            {
                customer.Gender = false;
            }

            if (!String.IsNullOrWhiteSpace(tDescription.Text))
            {
                customer.Description = tDescription.Text;
            }

            repository.addCustomer(customer);
            //MessageBox.Show("با موفقیت اضافه شد");
        }