Example #1
0
        public void Delete(DataForm Sfrm)
        {
            frm = Sfrm;
            foreach (Control ctrl in Sfrm.Controls)
            {
                string sql = CreateSqlStatement();
                DataLayer.ExecuteNonQuery(sql);

                //hemaily 8june 2013
                if (ctrl is HGrid)
                {
                    HGrid MyGrid = ctrl as HGrid;
                    sql = createDeleteStatementForGrid(MyGrid);
                    if (sql != "")
                        DataLayer.ExecuteNonQuery(sql);
                }
                //endhemaily
            }

            //frm.binder.Clear(frm.Controls);
            Clear(frm.Controls);

            //  MessageBox.Show("تم الحذف");
            NextCode(frm.NextCodeControl);
            frm.recordMode = DataForm.RecordMode.Insert;
        }
Example #2
0
        public void fillCombo(DataForm frm)
        {
            foreach (Control ctrl in frm.Controls)
            {
                if (ctrl is HComboBox)
                {
                    HComboBox co = ctrl as HComboBox;
                    if (co.TableName == "" || co.TableName == null) return;
                    else
                    {
                        string sql = @"   SELECT     COLUMN_NAME
                             FROM         INFORMATION_SCHEMA.COLUMNS
                             WHERE      (TABLE_NAME = '" + co.TableName + @"') and COLUMN_NAME = 'NotActive' ";
                        DataTable dt = DataLayer.executeDataTable(sql);

                        sql = "select * from " + co.TableName + " where 1=1 ";
                        if (dt.Rows.Count != 0)
                            sql += "  and isnull (NotActive,0) =0";
                        dt = DataLayer.executeDataTable(sql);
                        co.DataSource = dt;
                        //hemaily
                        co.SelectedIndex = -1;
                    }

                }
            }
        }
Example #3
0
        public void updateFooterTable(string header, string footer, DataForm frm)
        {
            string sql = "";

            if (frm.FormType == "FooterFormWithContol")
            {

                frm.recordMode = DataForm.RecordMode.Insert;

                #region  Create insert stament
                try
                {
                    foreach (Control ctrl in frm.Controls)
                        if (ctrl is HGrid && ctrl.Name != "List")
                        {
                            HGrid grd = ctrl as HGrid;
                            string sql_del = "delete from " + frm.TableName + " where 1=1 " + getCriteria(frm) + "";
                            DataLayer.executeNonQuery(sql_del);
                            // mohamed samir 28/9/2013
                            foreach (DataGridViewRow r in grd.Rows)
                            {
                                string[] InsStr = CreateSqlStatement().Split(new string[] { "(", "Values", ")" }, StringSplitOptions.None);

                                if (isEmptyRow(grd, r.Index) == false)
                                {

                                    foreach (DataGridViewColumn col in grd.Columns)
                                    {
                                        InsStr[1] += "," + col.Name;
                                        //hemaily 31may2013 اضافة سينجل كوت
                                        if (col.ValueType == typeof(string) || col.ValueType == null)
                                            InsStr[4] += ",'" + r.Cells[col.Name].Value + "'";
                                        if (col.ValueType == typeof(DateTime))
                                            InsStr[4] += ",'" + Convert.ToDateTime(r.Cells[col.Name].Value.ToString()).ToString("dd/MM/yyyy") + "'";
                                        else if (col.ValueType == typeof(Single) || col.ValueType == typeof(decimal) || col.ValueType == typeof(int) || col.ValueType == typeof(Boolean))
                                        {
                                            InsStr[4] += "," + r.Cells[col.Name].Value + "";
                                        }
                                    }
                                    DataLayer.executeNonQuery(InsStr[0] + "(" + InsStr[1] + ") values (" + InsStr[4] + ")");

                                }
                            }
                        }
                }
                catch (Exception ex) { }
                #endregion

            }
            else
            {
                try
                {

                    // Mohamed samir 22/5/2013
                    string Exist = "0";
                    Exist = DataLayer.Executescalar(@"SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
                           WHERE table_name = '" + footer + "' and column_name =  'BranchCode'");
                    string cri = "";
                    if (Exist == "1")
                    {
                        cri += " AND BranchCode = " + GlobalVariables.BranchCode;
                    }
                    // Mohamed samir 22/5/2013
                    sql = "delete from " + footer + " where 1=1 " + getCriteria(frm) + cri + "";
                    DataLayer.executeNonQuery(sql);
                    updateFooter(frm.Controls, header, footer);

                }
                catch (Exception ex) { }
            }
        }
Example #4
0
        public Boolean Save(DataForm Sfrm)
        {
            if (isRequired() == false)
            {
                //hemaily 18may2013
                if (Sfrm.FormType == "FooterFormWithOutContol")
                {

                    //hassan 28-9-2013
                    foreach (Control ctrl in frm.Controls)
                        if (ctrl is HGrid)
                        {
                            HGrid grd = ctrl as HGrid;
                            if (grd.TableName != null && grd.TableName != "")
                                updateFooterTable(frm.TableName, grd.TableName, frm);
                        }
                    //end heamily 18may2013
                    Clear(frm.Controls);
                    //MessageBox.Show("تم الحفظ");
                    frm.binder.NextCode(frm.NextCodeControl);
                    return true;
                }
                else if (Sfrm.FormType == "HeaderFooterContol")
                {
                    // Mohamed samir 22/5/2013
                    if (Sfrm.recordMode == DataForm.RecordMode.None)
                        Sfrm.recordMode = DataForm.RecordMode.Insert;
                    frm = Sfrm;

                    string sql = CreateSqlStatement();
                    if (DataLayer.ExecuteNonQuery(sql) > 0)
                    {
                        if (Sfrm.recordMode == DataForm.RecordMode.Insert)
                        {
                            Sfrm.recordMode = DataForm.RecordMode.Update;

                        }

                        //  hemail 18may2013
                        //foreach (Control ctrl in frm.Controls)
                        //    if (ctrl is HGrid)
                        //    {
                        //        HGrid grd = ctrl as HGrid;
                        //        if (grd.TableName != null && grd.TableName != "")
                        //            updateFooterTable(frm.TableName, grd.TableName, frm);
                        //    }
                        //// end heamily 18may2013
                        fillFooterTable(frm, frm.Controls);
                        Clear(frm.Controls);
                        MessageBox.Show("تم الحفظ");
                        frm.binder.NextCode(frm.NextCodeControl);
                        return true;
                        //  Mohamed samir 22/5/2013
                    }
                    else
                        return false;

                }
                else if (Sfrm.FormType == "FooterFormWithContol")
                {
                    // Mohamed samir 22/5/2013
                    if (Sfrm.recordMode == DataForm.RecordMode.None)
                        Sfrm.recordMode = DataForm.RecordMode.Insert;
                    frm = Sfrm;

                    updateFooterTable(frm.TableName, frm.TableName, frm);

                    // end heamily 18may2013
                    Clear(frm.Controls);
                    MessageBox.Show("تم الحفظ");
                    frm.binder.NextCode(frm.NextCodeControl);
                    return true;
                    //  Mohamed samir 22/5/2013

                }
                else
                //end hemaily 18may2013
                {
                    if (Sfrm.recordMode == DataForm.RecordMode.None)
                        Sfrm.recordMode = DataForm.RecordMode.Insert;
                    frm = Sfrm;

                    string sql = CreateSqlStatement();
                    if (DataLayer.ExecuteNonQuery(sql) > 0)
                    {
                        if (Sfrm.recordMode == DataForm.RecordMode.Insert)
                        {
                            Sfrm.recordMode = DataForm.RecordMode.Update;

                        }

                        MessageBox.Show("تم الحفظ");
                        //  frm.binder.NextCode(frm.NextCodeControl);

                        return true;
                    }
                    else
                        return true;

                }

            }

            else
            { return false; }
        }
Example #5
0
 public DataBinder(DataForm form)
 {
     frm = form;
     LaodControlsProperites();
 }
Example #6
0
        // Mohamed Samir 8/6/2012
        public string getCriteria(DataForm frm)
        {
            string critria = "";
            string Exist = "0";
            Exist = DataLayer.Executescalar(@"SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
                           WHERE table_name = '" + frm.TableName + "' and column_name =  'BranchCode'");

            if (Exist == "1")
            {
                critria += " AND BranchCode = " + GlobalVariables.BranchCode;
            }
            foreach (Control co in frm.Controls)
            {
                #region textbox

                if (co is HTextBox)
                {

                    HTextBox ht = co as HTextBox;
                    if (ht.FieldName != "" && ht.Text != "")
                    {
                        if (ht.key == true)
                        {
                            if (ht.DataType.ToString() != "DateTime")
                                critria += " and " + ht.FieldName + " = '" + ht.Text + "'";
                            //  else critria += " and "+ht.FieldName+"=convert(datetime,'"+ht.Text +"',102)";
                            else critria += " and " + ht.FieldName + "=convert(datetime,'" + Convert.ToDateTime(ht.Text).ToString("dd/MM/yyyy") + "',103)";
                        }
                    }
                }
                #endregion
            }
            return critria;
        }
Example #7
0
        public void fillFooterTable(DataForm frm, Control.ControlCollection Control)
        {
            foreach (Control ctrl in Control)
            {
                if (ctrl is HGrid)
                {
                    HGrid grd = ctrl as HGrid;
                    if(grd.TableName != null)
                    updateFooterTable(frm.TableName, grd.TableName, frm);
                }
                if (ctrl.Controls.Count != 0 && !(ctrl is HGrid))
                {
                    fillFooterTable(frm, ctrl.Controls);
                }

            }
        }