Example #1
0
        private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
            // Exit if no project list
            if (m_List == null)
            {
                return;
            }

            // Get the item affected
            int index = e.NewIndex;
            RotiToChooseItem changedItem = null;

            if ((index > -1) && (index < m_List.Count))
            {
                changedItem = m_List[index];
            }

            // Get the type of change that occured
            ListChangedType changeType = e.ListChangedType;

            // Dispatch a change handler

            switch (changeType)
            {
            case ListChangedType.ItemChanged:
                CommandUpdateRoti updateRoti = new CommandUpdateRoti(changedItem);
                m_AppController.ExecuteCommand(updateRoti);
                break;

            case ListChangedType.ItemMoved:
                // Not supported in this app
                break;
            }
        }
Example #2
0
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            //CommandSaveRotiList saveRoti = new CommandSaveRotiList(m_List);
            //m_AppController.ExecuteCommand(saveRoti);
            if (m_List == null)
            {
                return;
            }
            RotiToChooseItem changeItem = (RotiToChooseItem)bindingSource1.Current;

            if (changeItem == null)
            {
                return;
            }

            if (isNewRecord)
            {
                CommandInsertRoti newRoti = new CommandInsertRoti(changeItem);
                m_AppController.ExecuteCommand(newRoti);
            }
            else
            {
                CommandUpdateRoti updateRoti = new CommandUpdateRoti(changeItem);
                m_AppController.ExecuteCommand(updateRoti);
            }
        }
        private void importBtn_Click(object sender, EventArgs e)
        {
            if (dataGridView1.DataSource == null)
            {
                return;
            }
            if (sourceTxt.Text == "" && sheetTxt.Text == "")
            {
                return;
            }

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[7].Value.ToString() != null)
                {
                    RotiToChooseItem myItem = new RotiToChooseItem();
                    myItem.ItemCode    = row.Cells[0].Value.ToString();
                    myItem.ItemName    = row.Cells[1].Value.ToString();
                    myItem.ItemSort    = row.Cells[2].Value.ToString();
                    myItem.Brand       = row.Cells[3].Value.ToString();
                    myItem.Jenis       = row.Cells[4].Value.ToString();
                    myItem.Category    = row.Cells[5].Value.ToString();
                    myItem.SubCategory = row.Cells[6].Value.ToString();
                    myItem.Price       = Convert.ToDecimal(row.Cells[7].Value);

                    CommandInsertRoti importData = new CommandInsertRoti(myItem);
                    m_AppController.ExecuteCommand(importData);
                }
            }
        }
        public void ListRotiToChoose(RotiToChooseList rotiList)
        {
            //Build a query string
            string sql = string.Format("SELECT ITEMCODE, ITEMNAME, ITEMSORT, Brand, Jenis, Category, SubCategory, Price, Stat FROM [ITEM]");

            //Get a dataset from the query
            DataSet dataSet = DataProvider.GetDataSet(sql);

            //Create variables for dataset
            DataTable rotiTable = dataSet.Tables[0];

            //Load roti list from the database
            RotiToChooseItem nextRoti = null;

            foreach (DataRow parent in rotiTable.Rows)
            {
                nextRoti             = new RotiToChooseItem();
                nextRoti.ItemCode    = parent["itemCode"].ToString();
                nextRoti.ItemName    = parent["itemName"].ToString();
                nextRoti.ItemSort    = parent["itemSort"].ToString();
                nextRoti.Brand       = parent["Brand"].ToString();
                nextRoti.Jenis       = parent["Jenis"].ToString();
                nextRoti.Category    = parent["Category"].ToString();
                nextRoti.SubCategory = parent["SubCategory"].ToString();
                nextRoti.Price       = Convert.ToDecimal(parent["Price"]);
                nextRoti.Stat        = Convert.ToBoolean(parent["Stat"]);

                //Add the data item to the data list
                rotiList.Add(nextRoti);
            }

            //Dispose of the dataset
            dataSet.Dispose();
        }
        internal void CreateDatabaseRecord(RotiToChooseItem newRoti)
        {
            string sql = "INSERT INTO ITEM " +
                         "(ITEMCODE, ITEMNAME, ITEMSORT, Brand, Jenis, Category, SubCategory, Price, Stat)" +
                         " VALUES " +
                         "(@code, @name, @sort, @brand, @jenis, @category, @subcategory, @price, @stat)";

            AddorUpdateDatabaseRecord(sql, newRoti);
        }
        internal void UpdateDatabaseRecord(RotiToChooseItem updateRoti)
        {
            string sql = "UPDATE ITEM SET " +
                         "ITEMNAME = @name, " +
                         "ITEMSORT = @sort, " +
                         "Brand = @brand, " +
                         "Jenis = @jenis, " +
                         "category = @category, " +
                         "subcategory = @subcategory, " +
                         "price = @price, " +
                         "Stat = @stat " +
                         "WHERE ITEMCODE = @code";

            AddorUpdateDatabaseRecord(sql, updateRoti);
        }
Example #7
0
        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (m_List == null)
            {
                return;
            }

            var pesan = MessageBox.Show("Apakah Anda Yakin Ingin Menghapus ? ", "Penghapusan", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            if (pesan == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dgViewRoti.SelectedRows)
                {
                    RotiToChooseItem item = row.DataBoundItem as RotiToChooseItem;
                    if (item != null)
                    {
                        CommandDeleteRoti deleteItem = new CommandDeleteRoti(m_List, item);
                        m_AppController.ExecuteCommand(deleteItem);
                    }
                }
            }
        }
        protected void AddorUpdateDatabaseRecord(string sql, RotiToChooseItem itemMaster)
        {
            try
            {
                //Create and open a connection
                SqlConnection connection = new SqlConnection(m_ConnectionString);
                connection.Open();

                //create and configure a command
                SqlCommand command = new SqlCommand(sql, connection);

                //Adding value through parameter
                command.CommandType = System.Data.CommandType.Text;
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@code", itemMaster.ItemCode);
                command.Parameters.AddWithValue("@name", itemMaster.ItemName);
                command.Parameters.AddWithValue("@sort", itemMaster.ItemSort);
                command.Parameters.AddWithValue("@brand", itemMaster.Brand);
                command.Parameters.AddWithValue("@jenis", itemMaster.Jenis);
                command.Parameters.AddWithValue("@category", itemMaster.Category);
                command.Parameters.AddWithValue("@subcategory", itemMaster.SubCategory);
                command.Parameters.AddWithValue("@price", itemMaster.Price);
                command.Parameters.AddWithValue("@stat", itemMaster.Stat);

                //execute the command
                command.ExecuteNonQuery();

                //Close and dispose
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
Example #9
0
 public CommandUpdateRoti(RotiToChooseItem item)
 {
     m_Item = item;
 }
Example #10
0
 public CommandDeleteRoti(RotiToChooseList list, RotiToChooseItem item)
 {
     m_List = list;
     m_Item = item;
 }
Example #11
0
 public CommandInsertRoti(RotiToChooseItem item)
 {
     m_Item = item;
 }