Example #1
0
        private void Categories_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'medDbDataSet.Category' table. You can move, or remove it, as needed.
            this.categoryTableAdapter.Fill(this.medDbDataSet.Category);
            MedDbEntities   db         = new MedDbEntities();
            CatagoryDetails catDetails = new CatagoryDetails();

            catDetails.AddCatagoryParentNameToCombobox(cmb_CategoryHeadName);
            //var p = db.Categories.ToList();
            //DataTable dt = new DataTable();
            dgv_CategoryDetails.DataSource = db.Categories.ToList();
            //dgv_CategoryDetails.Refresh();
            //int rows = dgv_CategoryDetails.Rows.Count;

            //for (int i = 0; i < rows; i++)
            //{
            //    string s = dgv_CategoryDetails.Rows[i].Cells[2].FormattedValue.ToString();
            //    if (s != "")
            //    {
            //        dgv_CategoryDetails.Rows[i].Cells[3].Value = catDetails.getCategoryNameFromId(Convert.ToInt32(s));
            //    }
            //}
            //dgv_CategoryDetails.Refresh();
            Task.Delay(100).ContinueWith(t => load());
        }
Example #2
0
        private void dgv_CategoryDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string s = dgv_CategoryDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();

            if (s == "ترمیم")
            {
                CatagoryDetails.temp      = dgv_CategoryDetails.Rows[e.RowIndex].Cells[0].FormattedValue.ToString();
                txt_CategoryName.Text     = CatagoryDetails.temp;
                txt_CategoryDetails.Text  = dgv_CategoryDetails.Rows[e.RowIndex].Cells[1].FormattedValue.ToString();
                cmb_CategoryHeadName.Text = dgv_CategoryDetails.Rows[e.RowIndex].Cells[3].FormattedValue.ToString();
                categoryId = Convert.ToInt32(dgv_CategoryDetails.Rows[e.RowIndex].Cells[6].FormattedValue);
                editFlag   = true;
            }
            else if (s == "حزف کریں")
            {
                CatagoryDetails catDetails = new CatagoryDetails();
                catDetails.categoryId = Convert.ToInt32(dgv_CategoryDetails.Rows[e.RowIndex].Cells[6].FormattedValue);
                catDetails.Delete(catDetails.categoryId);
                MedDbEntities db = new MedDbEntities();
                var           p  = db.Categories.ToList();
                dgv_CategoryDetails.DataSource = db.Categories.ToList();
                int rows = dgv_CategoryDetails.Rows.Count;

                for (int i = 0; i < rows; i++)
                {
                    string s1 = dgv_CategoryDetails.Rows[i].Cells[2].FormattedValue.ToString();
                    if (s1 != "")
                    {
                        dgv_CategoryDetails.Rows[i].Cells[3].Value = catDetails.getCategoryNameFromId(Convert.ToInt32(s1));
                    }
                }
            }
        }
        public void AddCategoryToCombobox(ComboBox cmb)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Category c in db.Categories)
            {
                cmb.Items.Add(c.Text);
            }
            cmb.Refresh();
        }
        public void AddSymptomsToComboBox(ComboBox cmb)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Symptom s in db.Symptoms)
            {
                cmb.Items.Add(s.SymptomName);
            }
            cmb.Refresh();
        }
        public void AddCausesToComboBox(ComboBox cmb)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Reason r in db.Reasons)
            {
                //cmb.Items.Add(cmb);
            }
            cmb.Refresh();
        }
        public bool Edit()
        {
            MedDbEntities db     = new MedDbEntities();
            Category      catTbl = new Category();

            //foreach (Category c in db.Categories)
            //{
            //    if (c.Id == categoryId)
            //    {
            //        c.Text = catagoryName;
            //        c.Description = catagoryDescription;
            //        int parentCatId = getCatagoryIdFromCatagoryName(catagoryParentName);
            //        if (parentCatId != -1)
            //        {
            //            c.ParentId = parentCatId;
            //        }
            //        else
            //        {
            //            c.ParentId = null;
            //        }

            //        break;
            //    }
            //}
            //db.SaveChanges();
            //return true;
            if (categoryAlreadyExistsEdit(catagoryName))
            {
                return(false);
            }
            else
            {
                foreach (Category c in db.Categories)
                {
                    if (c.Id == categoryId)
                    {
                        c.Text        = catagoryName;
                        c.Description = catagoryDescription;
                        int parentCatId = getCatagoryIdFromCatagoryName(catagoryParentName);
                        if (parentCatId != -1)
                        {
                            c.ParentId = parentCatId;
                        }
                        else
                        {
                            c.ParentId = null;
                        }

                        break;
                    }
                }
                db.SaveChanges();
                return(true);
            }
        }
Example #7
0
        public void AddPotencyToComboBoxAloe(ComboBox cmb)
        {
            MedDbEntities db     = new MedDbEntities();
            var           result = db.Medicines.Where(p1 => p1.Type == "ایلو").Select(p2 => p2.Potency).Distinct();

            foreach (var v in result)
            {
                cmb.Items.Add(v);
            }
            cmb.Refresh();
        }
        public List <ReportData> Data()
        {
            List <ReportData> rptLst = new List <ReportData>();

            MedDbEntities db = new MedDbEntities();

            foreach (Disease d in db.Diseases)
            {
                ReportData    r     = new ReportData();
                List <string> tempR = new List <string>();
                List <string> tempS = new List <string>();
                List <string> tempM = new List <string>();
                r.EnglishName = d.EnglishName;
                r.UrduName    = d.UrduName;
                r.diseaseId   = d.Id;
                if (d.CategoryId == null)
                {
                    r.CategoryName = "";
                }
                else
                {
                    r.CategoryName = db.Categories.Find(d.CategoryId).Text;
                }
                IEnumerable <string> tempReasonLst = db.Diseases.First(a => a.Id == d.Id).Reasons.Select(r1 => r1.ReasonName);
                foreach (string s in tempReasonLst)
                {
                    tempR.Add(s);
                }
                IEnumerable <string> tempSymptomsLst = db.Diseases.First(a => a.Id == d.Id).Symptoms.Select(s1 => s1.SymptomName);
                foreach (string s in tempSymptomsLst)
                {
                    tempS.Add(s);
                }
                var tempMedLst = db.Medicines
                                 .Join(
                    db.DiseaseMedicines.Where(a => a.DiseaseId == d.Id),
                    d1 => d1.Id,
                    f => f.MedicineId,
                    (d1, f) => d1
                    ).ToList();
                foreach (var s in tempMedLst)
                {
                    tempM.Add(s.MedName);
                }
                r.ReasonNames = tempR;
                r.Medicines   = tempM;
                r.Symptoms    = tempS;
                rptLst.Add(r);
            }

            return(rptLst);
        }
Example #9
0
        public void AddTreatmentToComboBoxAloe(ComboBox cmb)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Medicine m in db.Medicines)
            {
                if (m.Type == "ایلو")
                {
                    cmb.Items.Add(m.MedName);
                }
            }
            cmb.Refresh();
        }
        public bool DiseaseAlreadyExist(string englishName, string urduName)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Disease d in db.Diseases)
            {
                if (d.EnglishName == englishName || d.UrduName == urduName)
                {
                    return(true);
                }
            }
            return(false);
        }
        public bool categoryAlreadyExists(string name)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Category c in db.Categories)
            {
                if (c.Text == name)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #12
0
        public int getIdFromNameTypePotency(string name, string type, string potency)
        {
            int           id = 0;
            MedDbEntities db = new MedDbEntities();

            foreach (Medicine m in db.Medicines)
            {
                if (m.MedName == name && m.Type == type && m.Potency == potency)
                {
                    id = m.Id;
                }
            }
            return(id);
        }
        public int getDiseaseIdFromName(string name)
        {
            int           id = 0;
            MedDbEntities db = new MedDbEntities();

            foreach (Disease d in db.Diseases)
            {
                if (d.UrduName == name)
                {
                    id = d.Id;
                }
            }
            return(id);
        }
        public void Delete(int id)
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Category c in db.Categories)
            {
                if (c.Id == id)
                {
                    db.Categories.Remove(c);
                    break;
                }
            }
            db.SaveChanges();
        }
        public int GetCatIdFromCatName(string name)
        {
            int           catId = -1;
            MedDbEntities db    = new MedDbEntities();

            foreach (Category c in db.Categories)
            {
                if (c.Text == name)
                {
                    catId = c.Id;
                }
            }
            return(catId);
        }
Example #16
0
        public void AddCauseToDb()
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Causes c in lstCause)
            {
                if (c.ReasonId == 0)
                {
                    Reason rTbl = new Reason();
                    rTbl.ReasonName = c.ReasonName;
                    db.Reasons.Add(rTbl);
                }
            }
            db.SaveChanges();
        }
Example #17
0
        public int getMedIdFromName(string name)
        {
            int           id = 0;
            MedDbEntities db = new MedDbEntities();

            foreach (Medicine m in db.Medicines)
            {
                if (m.MedName == name)
                {
                    id = m.Id;
                    break;
                }
            }
            return(id);
        }
        public void AddSymptomsToDb()
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Symptoms s in lstSym)
            {
                if (s.Id == 0)
                {
                    Symptom sTbl = new Symptom();
                    sTbl.SymptomName = s.SymptomName;
                    db.Symptoms.Add(sTbl);
                }
            }
            db.SaveChanges();
        }
        public int getSymIdFromName(string name)
        {
            int           id = 0;
            MedDbEntities db = new MedDbEntities();

            foreach (Symptom s in db.Symptoms)
            {
                if (s.SymptomName == name)
                {
                    id = s.Id;
                    break;
                }
            }
            return(id);
        }
Example #20
0
        public int getReasonIdFromName(string name)
        {
            int           id = 0;
            MedDbEntities db = new MedDbEntities();

            foreach (Reason r in db.Reasons)
            {
                if (r.ReasonName == name)
                {
                    id = r.ReasonId;
                    break;
                }
            }
            return(id);
        }
        public void Add(MedDbEntities db)
        {
            Disease diseaseTbl = new Disease();

            if (DiseaseAlreadyExist(englishName, urduName) == true)
            {
                errorEnglishName = "بیماری پہلے سے موجود ہے";
                errorUrduName    = "بیماری پہلے سے موجود ہے";
                return;
            }
            else if (NameHasDigit(urduName) == true || NameHasDigit(englishName) == true)
            {
                if (NameHasDigit(urduName))
                {
                    errorUrduName = "بیماری کا نام درست نہیں";
                }
                if (NameHasDigit(englishName))
                {
                    errorEnglishName = "بیماری کا نام درست نہیں";
                }
                return;
            }
            else
            {
                diseaseTbl.EnglishName = englishName;
                diseaseTbl.UrduName    = urduName;
                diseaseTbl.AddedOn     = DateTime.Now;
                diseaseTbl.UpdatedOn   = DateTime.Now;
                diseaseTbl.Description = description;
                int catId = GetCatIdFromCatName(categoryName);
                if (catId != -1)
                {
                    diseaseTbl.CategoryId = catId;
                }
                else
                {
                    diseaseTbl.CategoryId = null;
                }
                db.Diseases.Add(diseaseTbl);
                //Symptom a = db.Symptoms.Find(13);
                //diseaseTbl.Symptoms.Add(a);

                //db.SaveChanges();
                errorEnglishName = "";
                errorUrduName    = "";
                return;
            }
        }
Example #22
0
        //public void AddTypeToComboBox(ComboBox cmb)
        //{
        //    MedDbEntities db = new MedDbEntities();
        //    foreach (Medicine m in db.Medicines)
        //    {
        //        cmb.Items.Add(m.Type);
        //    }
        //    cmb.Refresh();
        //}

        public void AddPotencyToComboBox(ComboBox cmb)
        {
            MedDbEntities db = new MedDbEntities();
            //foreach (Medicine m in db.Medicines)
            //{
            //    cmb.Items.Add(m.Potency);
            //}
            //cmb.Refresh();
            var result = db.Medicines.Where(p1 => p1.Type == "طبی").Select(p2 => p2.Potency).Distinct();

            foreach (var v in result)
            {
                cmb.Items.Add(v);
            }
            cmb.Refresh();
        }
Example #23
0
        public void AddToDb()
        {
            MedDbEntities db = new MedDbEntities();

            foreach (Treatment t in lstMedicalTreatment)
            {
                if (t.Id == 0)
                {
                    Medicine mTbl = new Medicine();
                    mTbl.MedName = t.MedName;
                    mTbl.Type    = t.Type;
                    mTbl.Potency = t.Potency;
                    db.Medicines.Add(mTbl);
                }
            }
            db.SaveChanges();
        }
        public string getCategoryNameFromCategoryId(Nullable <int> id)
        {
            string        CategoryName = "";
            MedDbEntities db           = new MedDbEntities();

            if (id != null)
            {
                foreach (Category c in db.Categories)
                {
                    if (c.Id == id)
                    {
                        CategoryName = c.Text;
                        break;
                    }
                }
            }
            return(CategoryName);
        }
        public void ShowInGrid(DataGridView dgv)
        {
            List <DiseaseDetails> lst = new List <DiseaseDetails>();
            MedDbEntities         db  = new MedDbEntities();

            foreach (Disease d in db.Diseases)
            {
                DiseaseDetails dd = new DiseaseDetails();
                string         s  = getCategoryNameFromCategoryId(d.CategoryId);
                dd.Id           = d.Id;
                dd.UrduName     = d.UrduName;
                dd.EnglishName  = d.EnglishName;
                dd.CategoryId   = d.CategoryId;
                dd.CategoryName = s;
                lst.Add(dd);
            }
            dgv.DataSource = lst;
        }
 private void Details_Load(object sender, EventArgs e)
 {
     // TODO: This line of code loads data into the 'medDbDataSet4.Disease' table. You can move, or remove it, as needed.
     this.diseaseTableAdapter.Fill(this.medDbDataSet4.Disease);
     // TODO: This line of code loads data into the 'medDbDataSet4.Category' table. You can move, or remove it, as needed.
     this.categoryTableAdapter.Fill(this.medDbDataSet4.Category);
     DiseaseDetails d  = new DiseaseDetails();
     MedDbEntities  db = new MedDbEntities();
     //d.ShowInGrid(dgv_Details);
     //dgv_Details.DataSource = db.Diseases.ToList();
     //int rows = dgv_Details.Rows.Count;
     //for (int i = 0; i < rows; i++)
     //{
     //    if (dgv_Details.Rows[i].Cells[6].FormattedValue.ToString() != "")
     //    {
     //        dgv_Details.Rows[i].Cells[7].Value = d.getCategoryNameFromCategoryId(Convert.ToInt32(dgv_Details.Rows[i].Cells[6].FormattedValue.ToString()));
     //    }
     //}
 }
        public bool Add()
        {
            MedDbEntities db     = new MedDbEntities();
            Category      catTbl = new Category();

            if (categoryAlreadyExists(catagoryName) == true)
            {
                return(false);
            }
            else
            {
                catTbl.Text        = catagoryName;
                catTbl.Description = catagoryDescription;
                int parentCatId = getCatagoryIdFromCatagoryName(catagoryParentName);
                if (parentCatId != -1)
                {
                    catTbl.ParentId = parentCatId;
                }
                db.Categories.Add(catTbl);
                db.SaveChanges();
                return(true);
            }
        }
        public string getCategoryNameFromId(int id)
        {
            MedDbEntities db = new MedDbEntities();

            return(db.Categories.Find(id).Text);
        }
Example #29
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            errorFlag = false;
            lbl_errorCauseName.Text       = "";
            lbl_ErrorEnglishName.Text     = "";
            lbl_ErrorMedicalCureName.Text = "";
            lbl_ErrorPotency.Text         = "";
            lbl_ErrorSymptom.Text         = "";
            //lbl_ErrorType.Text = "";
            lbl_ErrorUrduName.Text = "";
            MedDbEntities db = new MedDbEntities();
            Diseases      d  = new Diseases();

            d.englishName  = txt_DiseaseEnglishName.Text;
            d.urduName     = txt_DiseaseUrduName.Text;
            d.description  = txt_DiseaseDetails.Text;
            d.categoryName = cmb_DiseaseCategory.Text;
            d.Add(db);
            if (d.errorUrduName != "" || d.errorEnglishName != "")
            {
                cmb_DiseaseCategory.Items.Clear();
                d.AddCategoryToCombobox(cmb_DiseaseCategory);
                lbl_ErrorEnglishName.Text      = d.errorEnglishName;
                lbl_ErrorEnglishName.ForeColor = System.Drawing.Color.Red;
                lbl_ErrorUrduName.Text         = d.errorUrduName;
                lbl_ErrorUrduName.ForeColor    = System.Drawing.Color.Red;
                txt_DiseaseEnglishName.Clear();
                txt_DiseaseUrduName.Clear();
                errorFlag = true;
            }
            Symptoms s = new Symptoms();

            if (Symptoms.lstSym.Count == 0)
            {
                lbl_ErrorSymptom.Text      = "علامت کا انتخاب کریں";
                lbl_ErrorSymptom.ForeColor = System.Drawing.Color.Red;
                errorFlag = true;
            }
            if (Causes.lstCause.Count == 0)
            {
                lbl_errorCauseName.Text      = "سبب کا ینتخاب کریں";
                lbl_errorCauseName.ForeColor = System.Drawing.Color.Red;
                errorFlag = true;
            }
            if (Treatment.lstMedicalTreatment.Count == 0)
            {
                lbl_ErrorMedicalCureName.Text      = "علاج کا انتخاب کریں";
                lbl_ErrorMedicalCureName.ForeColor = System.Drawing.Color.Red;
                //lbl_ErrorType.Text = "طرز کا انتخاب کریں";
                //lbl_ErrorType.ForeColor = System.Drawing.Color.Red;
                lbl_ErrorPotency.Text      = "قوت درج کریں";
                lbl_ErrorPotency.ForeColor = System.Drawing.Color.Red;

                lbl_ErrorTreatmentNameHomoeo.Text      = "علاج کا انتخاب کریں";
                lbl_ErrorTreatmentNameHomoeo.ForeColor = System.Drawing.Color.Red;
                lbl_ErrorPotencyHomoeo.Text            = "قوت درج کریں";
                lbl_ErrorPotencyHomoeo.ForeColor       = System.Drawing.Color.Red;

                lbl_ErrorTreatmentNameAloe.Text      = "علاج کا انتخاب کریں";
                lbl_ErrorTreatmentNameAloe.ForeColor = System.Drawing.Color.Red;
                lbl_ErrorPotencyAloe.Text            = "قوت درج کریں";
                lbl_ErrorPotencyAloe.ForeColor       = System.Drawing.Color.Red;

                errorFlag = true;
            }
            if (errorFlag == true)
            {
                MessageBox.Show("تفصیلات درست نہیں۔ تمام ٹیب دوبارہ دیکھیں۔ غلطیاں نمایاں کر دی گیؑ ہیں");
                return;
            }



            db.SaveChanges();

            s.AddSymptomsToDb();

            List <string> lstSymName = new List <string>();

            foreach (Symptoms s1 in Symptoms.lstSym)
            {
                string s2 = s1.SymptomName;
                lstSymName.Add(s2);
            }

            int diseaseId = d.getDiseaseIdFromName(d.urduName);

            foreach (string s3 in lstSymName)
            {
                MedDbEntities db1 = new MedDbEntities();

                int     symId = s.getSymIdFromName(s3);
                Disease dt    = new Disease();
                dt.Id = diseaseId;
                db1.Diseases.Add(dt);
                db1.Diseases.Attach(dt);
                Symptom st = new Symptom();
                st.Id = symId;
                db1.Symptoms.Add(st);
                db1.Symptoms.Attach(st);
                dt.Symptoms.Add(st);
                db1.SaveChanges();
            }
            Symptoms.lstSym.Clear();
            dgv_symptoms.DataSource = null;
            dgv_symptoms.Rows.Clear();



            Causes c = new Causes();

            c.AddCauseToDb();

            List <string> lstCauseName = new List <string>();

            foreach (Causes c1 in Causes.lstCause)
            {
                string ctemp1 = c1.ReasonName;
                lstCauseName.Add(ctemp1);
            }

            foreach (string s4 in lstCauseName)
            {
                MedDbEntities db2 = new MedDbEntities();

                int     causeId = c.getReasonIdFromName(s4);
                Disease dt      = new Disease();
                dt.Id = diseaseId;
                db2.Diseases.Add(dt);
                db2.Diseases.Attach(dt);
                Reason rt = new Reason();
                rt.ReasonId = causeId;
                db2.Reasons.Add(rt);
                db2.Reasons.Attach(rt);
                dt.Reasons.Add(rt);
                db2.SaveChanges();
            }
            Causes.lstCause.Clear();
            dgv_Causes.DataSource = null;
            dgv_Causes.Rows.Clear();

            Treatment t = new Treatment();

            t.AddToDb();

            foreach (Treatment t1 in Treatment.lstMedicalTreatment)
            {
                DiseaseMedicine dmTbl = new DiseaseMedicine();
                dmTbl.DiseaseId             = diseaseId;
                dmTbl.MedicineId            = t1.getMedIdFromName(t1.MedName);
                dmTbl.DoctorRecommendations = txt_DoctorsRecomendation.Text;
                db.DiseaseMedicines.Add(dmTbl);
                db.SaveChanges();
            }
            Treatment.lstMedicalTreatment.Clear();
            dgv_MedicalCure.DataSource = null;
            dgv_MedicalCure.Rows.Clear();


            cmb_DiseaseCategory.Items.Clear();
            d.AddCategoryToCombobox(cmb_DiseaseCategory);

            cmb_Symptom.Items.Clear();
            s.AddSymptomsToComboBox(cmb_Symptom);

            //cmb_CauseName.Items.Clear();
            //c.AddCausesToComboBox(cmb_CauseName);

            cmb_MedicalCure.Items.Clear();
            t.AddTreatmentToCombobox(cmb_MedicalCure);
            //cmb_Types.Items.Clear();
            //t.AddTypeToComboBox(cmb_Types);
            cmb_Potency.Items.Clear();
            t.AddPotencyToComboBox(cmb_Potency);

            cmb_TreatmentNameHomoeo.Items.Clear();
            t.AddTreatmentToComboBoxHomoeo(cmb_TreatmentNameHomoeo);
            cmb_PotencyHomoeo.Items.Clear();
            t.AddPotencyToComboBoxHomoeo(cmb_PotencyHomoeo);

            cmb_CauseName.Text       = "";
            cmb_DiseaseCategory.Text = "";
            cmb_MedicalCure.Text     = "";
            cmb_Potency.Text         = "";
            cmb_Symptom.Text         = "";
            //cmb_Types.Text = "";
            txt_DiseaseDetails.Text       = "";
            txt_DiseaseEnglishName.Text   = "";
            txt_DiseaseUrduName.Text      = "";
            txt_DoctorsRecomendation.Text = "";

            cmb_TreatmentNameHomoeo.Text         = "";
            cmb_PotencyHomoeo.Text               = "";
            txt_DoctorsRecommendationHomoeo.Text = "";

            cmb_TreatmentNameAloe.Text         = "";
            cmb_PotencyAloe.Text               = "";
            txt_DoctorsRecommendationAloe.Text = "";


            MessageBox.Show("تفصیلات محفوظ ہو چکی ہیں");



            //if (d.Add() == true)
            //{
            //    MessageBox.Show("بیماری محفوظ کر دی گیؑ ہے");
            //    txt_DiseaseEnglishName.Clear();
            //    txt_DiseaseUrduName.Clear();
            //    txt_DiseaseDetails.Clear();
            //    cmb_DiseaseCategory.Text = "";
            //}
            //else
            //{
            //    MessageBox.Show("بیماری کا نام پہلے سے موجود ہے");
            //}
        }
Example #30
0
        private void btn_SaveCategory_Click_1(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_CategoryDetails.Text) || string.IsNullOrWhiteSpace(txt_CategoryDetails.Text) ||
                string.IsNullOrEmpty(txt_CategoryName.Text) || string.IsNullOrWhiteSpace(txt_CategoryName.Text))
            {
                MessageBox.Show("کیٹیگری کا نام اور تفصیلات درج کریں");
                return;
            }
            if (editFlag == false)
            {
                CatagoryDetails catDetails = new CatagoryDetails();
                catDetails.catagoryName        = txt_CategoryName.Text;
                catDetails.catagoryDescription = txt_CategoryDetails.Text;
                catDetails.catagoryParentName  = cmb_CategoryHeadName.Text;
                if (catDetails.Add() == true)
                {
                    MessageBox.Show("!کیٹیگوری محفوز ہو چکی ہے");
                    MedDbEntities db = new MedDbEntities();
                    var           p  = db.Categories.ToList();
                    dgv_CategoryDetails.DataSource = db.Categories.ToList();
                    int rows = dgv_CategoryDetails.Rows.Count;

                    for (int i = 0; i < rows; i++)
                    {
                        string s = dgv_CategoryDetails.Rows[i].Cells[2].FormattedValue.ToString();
                        if (s != "")
                        {
                            dgv_CategoryDetails.Rows[i].Cells[3].Value = catDetails.getCategoryNameFromId(Convert.ToInt32(s));
                        }
                    }
                    txt_CategoryName.Clear();
                    txt_CategoryDetails.Clear();
                }
                else
                {
                    MessageBox.Show("کیٹیگی پہلے سے موجود ہے");
                    //catDetails.AddCatagoryParentNameToCombobox(cmb_CategoryHeadName);
                }
            }
            else
            {
                CatagoryDetails catDetails = new CatagoryDetails();
                catDetails.catagoryName        = txt_CategoryName.Text;
                catDetails.catagoryDescription = txt_CategoryDetails.Text;
                catDetails.categoryId          = categoryId;
                catDetails.catagoryParentName  = cmb_CategoryHeadName.Text;
                if (catDetails.Edit() == true)
                {
                    MessageBox.Show("!کیٹیگوری محفوز ہو چکی ہے");
                    MedDbEntities db = new MedDbEntities();
                    var           p  = db.Categories.ToList();
                    dgv_CategoryDetails.DataSource = db.Categories.ToList();
                    int rows = dgv_CategoryDetails.Rows.Count;

                    for (int i = 0; i < rows; i++)
                    {
                        string s = dgv_CategoryDetails.Rows[i].Cells[2].FormattedValue.ToString();
                        if (s != "")
                        {
                            dgv_CategoryDetails.Rows[i].Cells[3].Value = catDetails.getCategoryNameFromId(Convert.ToInt32(s));
                        }
                    }
                    txt_CategoryName.Clear();
                    txt_CategoryDetails.Clear();
                }
                else
                {
                    MessageBox.Show("کیٹیگی پہلے سے موجود ہے");
                }
            }
        }