private void transferButton_Click(object sender, EventArgs e)
        {
            if (clientId != 0)
            {
                #region Func
                if (string.IsNullOrWhiteSpace(nationalIdText.Text))
                {
                    err = new ErrorProvider();
                    err.SetError(nationalIdText, "يجب إدخال  الرقم القومي");
                }
                else
                {
                    if (err != null)
                    {
                        err.Clear();
                    }
                }

                if (string.IsNullOrWhiteSpace(unitType.Text))
                {
                    unitErr = new ErrorProvider();
                    err.SetError(unitType, "يجب إدخال نوع الوحدة المحول إليها  ");
                }
                else
                {
                    if (unitErr != null)
                    {
                        unitErr.Clear();
                    }
                }

                //Sql commands

                if (!string.IsNullOrWhiteSpace(unitType.Text) && !string.IsNullOrWhiteSpace(nationalIdText.Text) && unitType.Text != currentUnitState.Text)
                {
                    try
                    {
                        String selectUnit = "select ID from units where unit_type=" + int.Parse(unitType.Text.ToString());
                        c1.SQLCODE(selectUnit, false);
                        int unittyperetrie = 0;
                        while (c1.myReader.Read())
                        {
                            unittyperetrie = int.Parse(c1.myReader["ID"].ToString());
                        }
                        FunctionsClass.updtaeMyScriptHistory(clientId);
                        String sqlupdateToOld = "update ClientsUnits set RecoredState='O' where (client_id=" + clientId + " and RecoredState='N')";
                        c1.SQLUPDATE(sqlupdateToOld, false);

                        String sqlinsert = "insert into ClientsUnits(client_id,unit_id,RecoredState)values(" + clientId + "," + unittyperetrie + ",'N')";
                        c1.SQLUPDATE(sqlinsert, false);

                        String updateUnitsSql = "update units set available_units=available_units-1 where unit_type=" + int.Parse(unitType.Text);
                        c1.SQLUPDATE(updateUnitsSql, false);
                        updateUnitsSql = "update units set available_units=available_units+1 where unit_type=" + int.Parse(currentUnitState.Text);
                        c1.SQLUPDATE(updateUnitsSql, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("خطأ ف البيانات المدخلة");
                        Logger.WriteLog("[" + DateTime.Now + "] ExceptionString: " + ex.ToString() + " InnerException: " + ex.InnerException + " ExceptionMessage: " + ex.Message + ". [" + this.Name + "] By [" + SessionInfo.empName + "]");
                    }

                    //clear all errors
                    if (unitErr != null)
                    {
                        unitErr.Clear();
                    }
                    if (err != null)
                    {
                        err.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("خطأ ف البيانات المدخلة");
                }
            }
            #endregion
        }
        private void button4_Click(object sender, EventArgs e)
        {
            //validate
            if (string.IsNullOrWhiteSpace(nationalIDMota.Text))
            {
                err = new ErrorProvider();
                err.SetError(nationalIDMota, "يجب إدخال  الرقم القومي");
            }
            else
            {
                if (err != null)
                {
                    err.Clear();
                }
            }

            //insert into tanazolat
            if (err == null && MotnazelToComplete && motnazelID != 0 && !string.IsNullOrEmpty(MotnazelToNationalId))
            {
                try
                {
                    String motanazaElleh = MotnazelToNationalId;
                    String subquery      = "select ID from Clients where national_id='" + motanazaElleh + "'";
                    c1.SQLCODE(subquery, false);
                    int ToID     = 0;
                    int unitType = 0;
                    while (c1.myReader.Read())
                    {
                        ToID = int.Parse(c1.myReader["ID"].ToString());
                    }

                    if (ToID != 0 && motnazelID != 0)
                    {
                        String da     = tanazolDate.Value.ToString("yyyy/MM/dd");
                        String query1 = "insert into tanazolat (from_id,to_id,tanazol_date) values (" + motnazelID + "," + ToID + ",#" + da + "#)";
                        if (c1.SQLUPDATE(query1, false))
                        {
                            String query2 = "update Clients set TnazolState ='F' where id=" + motnazelID + "";
                            c1.SQLUPDATE(query2, false);
                            String query3 = "update Clients set TnazolState ='T' where id=" + ToID + "";
                            c1.SQLUPDATE(query3, false);
                            //We need to update aqsat history to be with the new client ID
                            String query4 = "update aqsat set client_id=" + ToID + ",details='تم نقل القسط بعد التنازل' where client_id=" + motnazelID + "";
                            c1.SQLUPDATE(query4, false);
                            String query5 = "update first_paids set client_id=" + ToID + " where client_id=" + motnazelID + "";
                            c1.SQLUPDATE(query5, false);
                            String query6 = "update T5sesMoney set client_id =" + ToID + " where client_id=" + motnazelID + "";
                            c1.SQLUPDATE(query6, false);
                            //
                            String unitTypeTanazolSql = "select * from ClientsUnits where client_id=" + motnazelID + " ORDER BY ClientsUnits.ID DESC";
                            c1.SQLCODE(unitTypeTanazolSql, false);
                            if (c1.myReader.Read())
                            {
                                unitType = int.Parse(c1.myReader["unit_id"].ToString());
                            }
                            String sql2 = "insert into ClientsUnits(client_id,unit_id,RecoredState)values(" + ToID + "," + unitType + ",'N')";
                            c1.SQLUPDATE(sql2, true);
                            FunctionsClass.updtaeMyScriptHistory(motnazelID);
                            this.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("خطأ ف البيانات المدخلة");
                    Logger.WriteLog("[" + DateTime.Now + "] ExceptionString: " + ex.ToString() + " InnerException: " + ex.InnerException + " ExceptionMessage: " + ex.Message + ". [" + this.Name + "] By [" + SessionInfo.empName + "]");
                }
            }
            else
            {
                MessageBox.Show("يوجد خطأ, اما انك لم تدخل بيانات العميل الجديد او أنك لم تدخل الرقم القومي للعميل القديم ");
            }
        }